Mail error php

mail error php

Often it's helpful to find the exact error message that is triggered by the mail() function. While the function doesn't provide an error directly, you can use. Definition and Usage. The error_get_last() function returns the last error that occurred (as an associative array). The associative array contains four keys: [. There are different ways errors can be detected while using the PHP mail function. If your mail does not send for any reason, you can try the. mail error php

Mail error php - commit error

mail

(PHP 4, PHP 5, PHP 7, PHP 8)

mail — Send mail

Description

mail(
    string,
    string,
    string,
    array string = [],
    string = ""
): bool

Parameters

Receiver, or receivers of the mail.

The formatting of this string must comply with » RFC 2822. Some examples are:

Subject of the email to be sent.

Message to be sent.

Each line should be separated with a CRLF (\r\n). Lines should not be larger than 70 characters.

Caution

(Windows only) When PHP is talking to a SMTP server directly, if a full stop is found on the start of a line, it is removed. To counter-act this, replace these occurrences with a double dot.

(optional)

String or array to be inserted at the end of the email header.

This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.

If an array is passed, its keys are the header names and its values are the respective header values.

Note:

Before PHP 5.4.42 and 5.5.27, repectively, did not have mail header injection protection. Therefore, users must make sure specified headers are safe and contains headers only. i.e. Never start mail body by putting multiple newlines.

Note:

When sending mail, the mail must contain a header. This can be set with the parameter, or a default can be set in .

Failing to do this will result in an error message similar to . The header sets also when sending directly via SMTP (Windows only).

Note:

If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822.

(optional)

The parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the sendmail option.

This parameter is escaped by escapeshellcmd() internally to prevent command execution. escapeshellcmd() prevents command execution, but allows to add additional parameters. For security reasons, it is recommended for the user to sanitize this parameter to avoid adding unwanted parameters to the shell command.

Since escapeshellcmd() is applied automatically, some characters that are allowed as email addresses by internet RFCs cannot be used. mail() can not allow such characters, so in programs where the use of such characters is required, alternative means of sending emails (such as using a framework or a library) is recommended.

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is .

Return Values

Returns if the mail was successfully accepted for delivery, otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

Changelog

VersionDescription
7.2.0 The parameter now also accepts an array.

Examples

Example #1 Sending mail.

Using mail() to send a simple email:

Example #2 Sending mail with extra headers.

The addition of basic headers, telling the MUA the From and Reply-To addresses:

Example #3 Sending mail with extra headers as array

This example sends the same mail as the example immediately above, but passes the additional headers as array (available as of PHP 7.2.0).

Example #4 Sending mail with an additional command line parameter.

The parameter can be used to pass an additional parameter to the program configured to use when sending mail using the .

Example #5 Sending HTML email

It is also possible to send HTML email with mail().

Note:

If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.

Notes

Note:

The SMTP implementation (Windows only) of mail() differs in many ways from the sendmail implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a is needed listening on a network socket (which can either on the localhost or a remote machine).

Second, the custom headers like , , and are not interpreted by the in the first place, but are parsed by PHP.

As such, the parameter should not be an address in the form of "Something <[email protected]>". The mail command may not parse this properly while talking with the MTA.

Note:

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.

For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Note:

The following RFCs may be useful: » RFC 1896, » RFC 2045, » RFC 2046, » RFC 2047, » RFC 2048, » RFC 2049, and » RFC 2822.

add a note

User Contributed Notes 15 notes

Anonymous

2 years ago

Anonymous

5 years ago

php at simoneast dot net

5 years ago

charles dot fisher at arconic dot com

4 years ago

pangz dot lab at gmail dot com

2 years ago

ABOMB

10 years ago

chris at ocproducts dot com

5 years ago

Ben Cooke

16 years ago

pavel.lint at vk.com

10 years ago

Porjo

12 years ago

eeeugeneee

5 years ago

rexlorenzo at gmail dot com

10 years ago

Max AT

10 years ago

php dot net at schrecktech dot com

17 years ago

To Top

Problems Sending Mails

Author: Christian Sommer (doc)

 

Mail function in WB 2.5.x - 2.6.4

Within the WB development process, the mail function was updated several times. Up to WB v2.6.4, mails are send by the PHP function mail() .

 

Disadvantages of the PHP mail() function

In some cases, mails send via PHP mail() did not receive the recipients although it was send by WB without any error message. The most common reasons for that issue are listed below.

  • wrong format of mail header or content (e.g. differences in line break between Windows/Unix)
  • sendmail not installed or configured on your server (php.ini)
  • the mail provider of the recipeint does not allow mails send by PHP mail(); common spam protection

Errors in the format of header or content can cause that mails are treated as SPAM. In the best case, such mails are transfered to the spam folder of your recipient inbox or send back to the sender. In the worst case, such mails are deleted without any comment. If sendmail is not installed or not configured, no mails can be send at all.

It is common practice by free mail provider such as GMX, to reject mails send via the PHP function mail(). Very often such mails are deleted without any information of the recipient.

Wrap up: PHP mail()
Sending mails via the PHP mail() function is not very reliable. Even if WebsiteBaker is able to send the mail corretly, it may not achieve your recipient. The only way which is promising for the future is using SMTP for outgoing mails.

 

Mail function since WB 2.6.5

Due to the bad experiences with the PHP mail() function, the new mailer class: PHPMailer was introduced with WB v2.6.5. Some features of this mail class are listed below.

  • choose between different mail functions like PHP mail() or SMTP
  • support of SMTP authentification (password and user name)
  • support of multiple TOs, CCs, BCCs und REPLY-TOs addresses
  • independent of the operating system used (Linux/Unix/Mac/Windows)
  • possible to add attachments
  • possible to send mails in HTML format

The integration of the new PHPMailer class was done in a way to ensure backwards compatibility. As in the previous WB versions, the default setting for outgoing mails is set to PHP mail().

 

Sending mails via SMTP

If your service provider does support outgoing mails via SMTP without authentification, you should change the default setting from PHP mail() to SMTP mail. The following information is required to use SMTP:

  • SMTP host (e.g. smtp.yourdomain.com)
  • ensure that no authentification is required (not supported so far)

Replace the domain name by the SMTP host of your service provider.

 

Premises for sending mails

To send mails via PHP mail() or SMTP from WebsiteBaker v2.6.5 onwards, the following premises needs to be fulfilled.

  • a formally valid FROM: address (of the used domain)
  • at least one formaly valid TO: address
  • a formally valid Server mail address (WB backend: Settings -> Show advanced Options)

Note:
Some free mail provider like GMX reject all mails which uses a GMX address (e.g. [email protected]@gmx.net), but are not send via the GMX mail server.

Tip: To avoid such problems, one should use a FROM: address and Server mail following a syntax like: [email protected]@yourdomain.com

Preview:
Since WB 2.7 it is allowed to configure the mailer settings viat the WebsiteBaker backend. In addition the support for authentification will be included by default.

 

My server requires SMTP authentification

If your server requires SMTP authentification, you have to configure the mail settings in
Settings > Show Advanced Options > Mailer Settings

img WB Mailer Settings

Hervé wrote: ↑Thu May 14, 2020 8:11 am I still can't send a mass mail with the dedicated phpBB function.
I wrote a small php script that works very well : so there must be an error in the phpBB one.

Agree that it at least means there is something the PHP mail() process on this server perhaps "doesn't like" about the specific headers or data that phpBB is preparing. And your test script possibly prepares a more plain or simple example of sending mail, without anything like base64 encoding or UTF-8 involved, no abuse headers, etc.

The process that actually gets invoked when an application calls PHP mail() is not "just one thing" or the same for everyone; the person who setup the server and installed PHP gets to define what process actually gets called. And even when it is the default sendmail process, the configuration and restrictions of the sendmail processing itself can also be unique to the server, and/or have its own rules for what's considered spam, etc.

It's just hard to make a blanket agreement that "there must be an error in phpBB" when this same code works for the majority using the PHP mail() method of sending mail from phpBB. But it's not impossible; and regardless, we need to find the reason its failing on this server, whether it turns out to be unique to this hosting provider and server or not.

phpBB is currently reporting as much information as it can that is returned from the PHP mail() function. But as you can see, the function itself only returns TRUE or FALSE to indicate success or failure. Which means "the real information" for why the attempt to call PHP mail() failed is "in the logging of whatever process PHP mail() is configured to invoke on your server."

Which typically, only your hosting provider would have access to, and could tell you what the logs show for why the mail sending attempt failed. Because the information phpBB knows is typically only "the PHP mail() function returned FALSE."

I've used custom modifications like the one in the functions_messenger.php attached hereto try and figure out differences in the headers and data phpBB was preparing for the PHP mail() function to consume. Just in case you wanted to experiment that way, to use your PHP test script to try and mimic more and more aspects of what you see phpBB attempting to do. To see what specific aspect you have to emulate before the issue starts.

But that seems more like just for curiosity, and the solution is still only going to come from talking to your hosting provider. And having them review what logs they have access to for revealing why the mail sending attempt actually failed -- and what could be done about it -- regardless of which header or data item you narrow it down to beforehand.

Or if your hosting provider gives you SMTP server name / port / credentials to use in web applications running on your server, you could switch phpBB to send email directly through the SMTP server (instead of using PHP mail()), which would give you visibility into at least what the SMTP server knows and errors returned during the SMTP session.

Which will definitely be "more information than the phpBB ACP Error log has during PHP mail()"; but doesn't mean the same issue will occur with this method, or that the failure will be known before the SMTP session finishes.

How can I get the error message for the mail function

Your comment on this question:

1 answer to this question.

Your answer

Your comment on this answer:

Related Questions In Laravel

Subscribe to our Newsletter, and get personalized recommendations.

Already have an account? Sign in.

webinarREGISTER FOR FREE WEBINARX
webinar_successThank you for registeringJoin Edureka Meetup community for 100+ Free Webinars each monthJOIN MEETUP GROUP
Optional
This parameter is used to pass any additional email headers like From, Cc and Bcc. Each additional headers should be separated with a CRLF (\r\n).
Note: While sending the email, make sure there is a From header. You can set the From header, either by using the additional_headers parameter or, you can also set a default value in php.ini.

 

additional_parameters
String Optional
This parameter is used to pass any additional email headers like From, Cc and Bcc. Each additional headers should be separated with a CRLF (\r\n).
Note: While sending the email, make sure there is a From header. You can set the From header, either by using the additional_headers parameter or, you can also set a default value in php.ini.

 

additional_parameters
String

Hervé wrote: ↑Thu May 14, 2020 8:11 am I still can't send a mass mail with the dedicated phpBB function.
I wrote a small php script that works very well : so there must be an error in the phpBB one.

Agree that it at least means there is something the PHP mail() process on this server perhaps "doesn't like" about the specific headers or data that phpBB is preparing. And your test script possibly prepares a more plain or simple example of sending mail, without anything like base64 encoding or UTF-8 involved, mail error php, no abuse headers, etc.

The process that actually gets invoked when an application calls PHP mail() is not "just one thing" or the same for everyone; the person who setup the mail error php and installed PHP gets to define what process actually gets called. And even when it is the default sendmail process, the configuration and restrictions of the sendmail processing itself can also be unique to the server, and/or have its own rules for what's considered spam, etc.

It's just hard to make a blanket agreement that "there must be an error in phpBB" when this same code works for the majority using the PHP mail() method mail error php sending mail from phpBB. But it's not impossible; and regardless, we need to find the reason its failing on this server, whether it turns out to be unique to this hosting provider and server or not.

phpBB is currently reporting as much information as it can that is returned from the PHP mail() function. But as you can see, the function itself only returns TRUE or FALSE to indicate success or failure. Which means "the real information" for why the attempt to call PHP mail() failed is "in the logging of whatever process PHP mail() is configured to invoke on your server."

Which typically, only your hosting provider would have access to, and could tell you what the logs show for why the mail sending attempt failed. Because the information phpBB knows is typically only "the PHP mail() function returned FALSE."

I've used custom modifications like the one in the functions_messenger.php attached hereto try and figure out differences in the headers and data phpBB was preparing for the PHP mail() function to consume. Just in case you wanted to experiment that way, to use your PHP test script to try and mimic more and more aspects of what you see phpBB attempting to do, mail error php. To see what specific aspect you have to emulate before the issue starts.

But that seems more like just for curiosity, and the solution is still only going to come from talking to your hosting provider. And having them review what logs they have access to for revealing why the mail sending attempt actually failed -- and what could be done about it -- regardless of which header or data item you narrow it down to beforehand.

Or if your hosting provider gives you SMTP server name / port / credentials to use in web applications running on your server, you could switch phpBB to send email directly through the SMTP server (instead of using PHP mail()), which would give you visibility into at least what the SMTP server knows and errors returned during the SMTP session.

Which will definitely be "more information than the phpBB ACP Error log has during PHP mail()"; but doesn't mean the same issue will mail error php with this method, or that the failure will be known before the SMTP session finishes.

Troubleshooting common issues with PHP Mail critical error dea1

Let's Get Started

Check the spam folder

If php mail is not reaching a recipient's inbox, investigation can begin by checking the spam folder.

If php mail is going to spam, it may be necessary to update the spam filter of the receiver, such as whitelisting ati mom.implementation error sender address.

Third-party search engines such as https://mxtoolbox.com/blacklists.aspx can be used to check if the domain is listed on Real Time Blacklists (RBL). Spam testers such as https://www.mail-tester.com/ can be used to check the probability of an email getting marked as spam.

Check for bounceback messages

Bounceback messages will often contain important information as to why email is undelivered, mail error php. If you or your contact are receiving bouncebacks, we recommend reviewing the additional documentation below:

Send a php test to different test accounts

Sending to different mail hosts can help determine if the issue is domain specific.

For example, if @gmail.com users are not receiving php mail, mail error php, then additional tests can be sent to @yahoo.com, @hotmail.com, and/or @aol.com.

Create a simple php mail tester

It can be helpful for testing to use a generic php mail script, mail error php, as this can help eliminate the effects of third-party variants. To assist you, we have provided a sample php mail script which can be added to your site's root directory via File Manager, FTP, or SSH. After adding this file, it can be accessed through a web browser to send a php test to a desired address.

Filename: email.php

<?php
if (isset($_REQUEST['to']))
{
$to = $_REQUEST['to'];
$to = htmlspecialchars($to);
$host=$_SERVER['SERVER_NAME'];
$ip=$_SERVER['SERVER_ADDR'];
$from="[email protected]$host";
$subject="PHP Mail Test";
$message="This is a test message sent from $host. It originated from the IP address $ip. If you received this email, that means that the PHP mail function is working on this server.";
$headers="From: $from"mail error php. "\r\n"mail error php. "Reply-To: [email protected]$host". "\r\n". "X-Mailer: PHP/". phpversion();
$success=mail($to,$subject,$message,$headers);

$regex = '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
if (preg_match($regex, $to)) {

if($success) {
echo "The email was sent successfully";
}
else {
echo "An error occurred, and the email was not sent. Check your domains' error logs and mail log for more info.";
}

} else {

echo "
<center></br>
<form method='post' action='email.php'><br>PHP mail() Test<br>
To: <input name='to' type='text'>
<input type='submit'>
</form><font color='red'>";

echo $to. " is an invalid email. Please try again.</font></center>";

}}

else
{
echo "<center></br>
<form method='post' action='email.php'><br>PHP mail() Test<br>
To: <input name='to' type='text'>
<input type='submit' value='Send Message'>
</form></center>";
}

?>

If php mail is received while using a generic script, then it can be determined that the server's php mail is functional.

If you are still unable to receive php mail using a third-party application, that would indicate the issue's origin to be at the development level. In this case, it would be advised to contact your website's developer for further troubleshooting.

Checking PHP Mail Logs

Checking mail logs can provide insight as to what exactly is occurring when php mail is attempted by your server. The log locations we would recommend checking is as followed:

Plesk:
/usr/local/psa/var/log/maillog

cPanel:
/var/log/exim_mainlog

For the Managed WordPress Hosting, the php mail function is active and usable. However, this is not recommended, as we may be limited in our ability to support php mail on this server type. Some suggested alternatives can include third-party API solutions such error 26 turbo pascal https://www.mailgun.com/ or https://sendgrid.com/

For information and suggestions on migrations feel free to contact our Support Staff by submitting a support request, opening a support chat, or by calling us at 1.310.841.5500.

mail

(PHP 4, mail error php, PHP 5, PHP 7, PHP 8)

mail — Send mail

Description

mail(
    string,
    string,
    string,
    array Required
The content of the mail that you want to send. Each line of the email should be separated with a CRLF (\r\n) and each line should not exceed 70 characters.
In case of Windows machine, when PHP is connecting to error configuration specifies use_bayes 0, sa-learn disabled SMTP server to sendmail, it removes a full stop which is found at the start of a mail error php. To resolve this, replace the dot with a double dot, using the below code:

<?php $text = str_replace("\n.", "\n.", mail error php, $text); ?>

 

additional_headers
mixed (String or Array) Optional
This additional_parameter can be used to pass additional flags to the Sendmail program as configured in the sendmail_path configuration setting. For example; you can use this parameter to set the envelope sender address when using Sendmail with -f option. PHP by mail error php internally escape the values coming in this parameter with escapeshellcmd() to prevent any potential command execution.

 

Return Value

mail() function returns TRUE if the SMTP server successfully accepted the mail for delivery, else FALSE.

Getting TRUE doesn't necessarily mean that the email is delivered to the recipient's server. TRUE is just an indication that your mail has successfully internal error 2739 vypress chat to the SMTP server's queue for sending.
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will reach the intended destination.

 

Note: mail() function will not work in Local server. A server connected to the internet and SMTP ports opened will be required to send mail.

Few Use Cases and Working Examples

1. How to send an HTML mail

<?php $to = "[email protected], [email protected]"; $subject = "This is a test HTML email"; $message = " <html> <head> <title>This is a test HTML email</title> </head> <body> <p>Test email. Please ignore.</p> </body> </html> "; // It is mandatory to set the content-type when sending HTML email $headers = "MIME-Version: 1.0". "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8". "\r\n"; // More headers. From is required, rest other headers are optional $headers .= 'From: <[email protected]>'. "\r\n"; $headers .= 'Cc: [email protected]'. "\r\n"; mail($to,$subject,$message,$headers); ?>

 

2. How to sendmail with an additional command line parameter.
As described above, for this use case, you need to use the additional_parameters parameter to pass an additional parameter to the program configured to used when sending mail using the mail error php mail('[email protected]', 'This is a test subject line', 'The complete body of the message', null, '[email protected]'); ?>

Common Errors/Exceptions with PHP sendmail function

  1. Unable to send a large volume of emails using mail() function
    Using a mail() function is not recommended for sending large volume emails, because it opens and closes an SMTP socket connection for each email. This is really not very efficient.
    If you want to send a large amount of emails in PHP, mail error php, then it is recommended to refer PEAR::Mail, and PEAR::Mail_Queue packages or use some good Email Service Provider which can help you scale your email volume.
  2. Not receiving emails sent through PHP mail() function
    While there can be N number of reason for the failure, but one the wried problem which many encounters is with the Unix mail transfer agents, which replace LF by CRLF automatically, which leads to doubling CR if CRLF is already used in your code. In such a case, try using an LF (\n) only. Read more about message format on RFC 2822.
  3. Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing.
    This error occurs mostly because while sending mail, you have not mentioned the From header using the additional_headers parameters.

Configuring PHP for sending mail

In order to configure mail error php related to PHP you need to change `php.ini` file. So, we will be editing php.ini file in order to configure Sendmail.

You can easily locate or search your php.ini file in Linux using below command:

locate php.ini

 

The default location is `/etc/php.ini` 

You can find the same in windows where XAMPP or LAMPP is installed:

`C:\xampp\php\php.ini`

Clarification:

  • Xampp (X (for "some OS"), Apache, MySQL, Perl, PHP)
  • Lampp (Linux, Apache, MySQL, Perl, PHP)

Changing  php.ini file to add mail configuration.

1. Open your php.ini file using below:

For Linux/Mac OS:

vim /etc/php.in


For Windows:
using notepad
 

2. Search [mail function] in the file. It will be as shown below:

[mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = [email protected] ; For Unix only. You may supply arguments as well (default: "sendmail -t -i"), mail error php. ; http://php.net/sendmail-path sendmail_path = /usr/sbin/sendmail -t -i ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters = ; Add X-PHP-Originating-Script: that ricoh 4015 error e42 mail error php uid of the script followed by the filename mail.add_x_header = On ; The path to a log file that will log all mail() calls. Log entries include ; the full path of the script, line number, To address and headers. ;mail.log =

3, mail error php. Add your mail server details to the file or incase you have one you can change it (mail server can be your own ie. local mail server or you can use any ESP as a mail server).
For Linux/Mac OS:
- Check for `sendmail_path` and ensure; is not (semicolon is used to show the line is commented).
- By default it will use `/usr/bin/sendmail -t -i` you can change it if you are using any custom path.For Window:
- Check for `SMTP = localhost` and change it to your desired mail server (any ESP or localhost) no changes are required if you are using your own local server.
- Or you can also use the smtp server of any Email Service Provider like Pepipost, mail error php, Sendgrid, Mailgun, Sparkpost.

4, mail error php. Save/close the php.ini file

5. The final step, don’t forget to restart your webserver/php-fpm.

Pro tip: You can host a simple “info.php” on your webserver to check each and every configuration of your PHP using below 2 liner code:

vim php_info.php <?php phpinfo(); ?>

Save and exit the file.
6. Reload you webserver and php-fpm.
7. Hit http://localhost/php_info.php on your web browser.

Conclusion

Hope, this tutorial is able to help you send mail using PHP.

In case you are facing some issues mail error php are not mail error php above in the tutorial, or you have some suggestions, then please feel free to contribute below in comments.

Emails landing in spam?

The most common reason for emails landing in spam is the domain or IP blacklist. Use tools to check the blacklist status and ways to improve your email delivery.

Free Blacklist CheckScans across 100+ DNSBLs
string = [],
    string = ""
): bool

Parameters

Receiver, or receivers of the mail.

The formatting of this string must comply with » RFC 2822. Some examples are:

mail error php Subject of the email to be sent.

Message to be sent.

Each line should be separated with a CRLF (\r\n). Lines should not be larger than 70 characters.

Caution

(Windows only) When PHP is talking to a SMTP server directly, if a full stop is found on the start of a line, it is removed. To counter-act this, mail error php, ads error 7010 replace these occurrences with a double dot.

(optional)

String or array to be inserted mail error php the end of the email header.

This is typically used to add extra mail error php (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.

If an array is passed, its keys are the header names and boot error bootmgr is missing values are the respective header values.

Note:

Before PHP 5.4.42 and 5.5.27, repectively, did not have mail header injection protection. Therefore, users must make sure specified headers are safe and contains headers only. i.e. Never start mail body by putting multiple newlines.

Note:

When sending mail, the mail must contain a header, mail error php. This can be set with mail error php parameter, or a default can be set in.

Failing to do this will result in an error message similar to. The header sets also when sending directly via SMTP (Windows only).

Note:

If messages are not received, try using a LF (\n) only. Some Unix mail transfer agents (most notably » qmail) replace LF by CRLF mail error php automatically (which leads to doubling CR if CRLF is used). This should be a last resort, as it does not comply with » RFC 2822. to fixdayz error bad cd key

(optional)

The parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the sendmail option, mail error php.

This parameter is escaped by escapeshellcmd() internally to prevent command execution. escapeshellcmd() prevents command execution, but allows to add additional parameters. For security reasons, mail error php, it is recommended for the user to sanitize this parameter to avoid adding unwanted parameters to the shell command.

Since escapeshellcmd() is applied automatically, some characters that are allowed as email addresses by internet RFCs cannot be used. mail() can not allow such characters, so in programs where the use of such characters is required, alternative means of sending emails (such as using a framework or a library) is recommended.

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from mail error php added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is.

Return Values

Returns if the mail was successfully accepted for delivery, otherwise.

It is important to note that just mail error php the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.

Changelog

VersionDescription
7.2.0 The parameter now also accepts an array.

Examples

Example #1 Sending mail.

Using mail() to send a simple email:

Example #2 Sending mail with extra headers.

The addition of basic headers, telling the MUA the From and Reply-To addresses:

Example #3 Sending mail with extra headers as array

This example sends the same mail as the example immediately above, but passes the additional headers as array (available as of PHP 7.2.0).

Example #4 Sending mail with an additional command line parameter.

The parameter can be used to pass an additional parameter to the program configured to use when sending mail using the.

Example #5 Sending HTML email

It is also possible to send HTML email with mail().

Note:

If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.

Notes

Note:

The SMTP implementation (Windows only) of mail() differs in many mail error php ways from the sendmail implementation. First, it doesn't use a local binary mail error php for composing messages but only operates on direct sockets which means a is needed listening on a network socket (which can either on the localhost or a remote machine).

Second, the custom headers like and are not interpreted by the mail error php in the first place, but are parsed by PHP.

As such, the parameter should not be an address in the form of "Something <[email protected]>". The mail command may not parse this properly while talking with mail error php MTA. mail error php

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens mail error php closes an SMTP socket for each email, which is not very efficient.

For the sending of large amounts of email, see the » PEAR::Mail, and » PEAR::Mail_Queue packages.

Note:

The following RFCs may be useful: » RFC 1896, » RFC 2045, » RFC 2046, » RFC 2047, » RFC 2048, » RFC 2049, and » RFC 2822.

add a note

User Contributed Notes 15 notes

Anonymous

2 years ago

Anonymous

5 years ago

php at simoneast dot net

5 years ago

charles dot fisher at arconic dot com

4 years ago

pangz dot lab at gmail dot com

2 years ago

ABOMB

10 years ago

chris at ocproducts dot com

5 years ago

Ben Cooke

16 years ago

pavel.lint at vk.com

10 years ago

Porjo

12 years ago

eeeugeneee

5 years ago

rexlorenzo at gmail dot com

10 years ago

Max AT

10 years ago

php dot net at schrecktech dot com

17 years ago

To Top