Php mail fails no error



Php mail fails no error

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

mail — Send mail

Description

Parameters

Receiver, or receivers of the mail.

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

  • user@example.com
  • user@example.com, anotheruser@example.com
  • User
  • User , Another User

Subject of the email to be sent.

Subject must satisfy » RFC 2047.

Message to be sent.

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

(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.

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.

Before PHP 5.4.42 and 5.5.27, repectively, additional_headers 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.

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

Failing to do this will result in an error message similar to Warning: mail(): «sendmail_from» not set in php.ini or custom «From:» header missing . The From header sets also Return-Path when sending directly via SMTP (Windows only).

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.

The additional_params 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 sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f 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 /etc/mail/trusted-users .

Return Values

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 actually reach the intended destination.

Читайте также:  Error using steam games

Changelog

Version Description
7.2.0 The additional_headers parameter now also accepts an array .

Examples

Example #1 Sending mail.

Using mail() to send a simple email:

// The message
$message = «Line 1\r\nLine 2\r\nLine 3» ;

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap ( $message , 70 , «\r\n» );

// Send
mail ( ‘caffeinated@example.com’ , ‘My Subject’ , $message );
?>

Example #2 Sending mail with extra headers.

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

= ‘nobody@example.com’ ;
$subject = ‘the subject’ ;
$message = ‘hello’ ;
$headers = ‘From: webmaster@example.com’ . «\r\n» .
‘Reply-To: webmaster@example.com’ . «\r\n» .
‘X-Mailer: PHP/’ . phpversion ();

mail ( $to , $subject , $message , $headers );
?>

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).

= ‘nobody@example.com’ ;
$subject = ‘the subject’ ;
$message = ‘hello’ ;
$headers = array(
‘From’ => ‘webmaster@example.com’ ,
‘Reply-To’ => ‘webmaster@example.com’ ,
‘X-Mailer’ => ‘PHP/’ . phpversion ()
);

mail ( $to , $subject , $message , $headers );
?>

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

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

Example #5 Sending HTML email

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

// Multiple recipients
$to = ‘johny@example.com, sally@example.com’ ; // note the comma

// Subject
$subject = ‘Birthday Reminders for August’ ;

// Message
$message = ‘

Birthday Reminders for August

Источник

No errors.But SMTP fails to send #258

Comments

I am trying to integrate PHPMail into an html template plugin for elgg framework which works fine with php mail(..) function. I need smtp support in the plugin so I’m trying to use PHPMailer on my hosted website. The send() executes correctly and returns true but mail does not go.
I created a local installation of elgg(on WAMP) to see if its a problem of the server but I get the same issue.I am using hMailserver as the mail server (smtp) for the local installation.
The code used inside the plugin is as follows:

hMailserver Mail logs look like this>>>>

Any idea whats wrong with this .

The text was updated successfully, but these errors were encountered:

The SENT: 530 SMTP authentication is required is the important bit — looks like it’s asking for something that PHPMailer doesn’t understand — it should be clear from its EHLO response. You have enabled debug output — what does it say? It’s a good idea to test this outside your main environment (i.e. the script by itself) so you can avoid problems that that may be introducing.

I made changes like this
$mail->AuthType =’PLAIN’;
$mail->Debugoutput=’error_log’;

I enabled error_log for debug but all I see in apache error log is:

[Thu Jul 17 06:28:38 2014] [error] [client 127.0.0.1] PHP WARNING: 2014-07-17 10:28:38 (UTC): «mail() [function.mail]: SMTP server response: 530 SMTP authentication is required.» in file C:\wamp\www\elgg\engine\lib\notification.php (line 365), referer: http://localhost/elgg/contactus/add

However when I ran Thunderbird to send using the same SMTP these are the logs on successful send:

Источник

Почему PHP функция mail() не работает на сервере?

Все время выдает ошибку. Вроде бы сервер нормально настроили, все пакеты поставили, пути проверили, а не работает.
Практически такой же сервер нормально работает с mail().

Что проверить? На что обратить внимание? Что обновить?

  • Вопрос задан более трёх лет назад
  • 32278 просмотров

Проверьте работает ли вообще функция mail на сервере:
echo «Testing» | mail -s «Test» test@example.com

Проверьте установлена ли почтовая служба: sendmail, postfix или другая.
Проверьте запущена ли почтовая служба.

Для sendmail/postfix проверьте настройки в php.ini:

Проверьте в php.ini не внесена ли функция mail в список запрещённых функций:
disable_functions

Вот что там отключено: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority

Есть что-то способное повлиять на мою проблему?

pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,
pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,
pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,
pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority

Источник

Php mail fails no error

The behaviour of these functions is affected by settings in php.ini .

Mail configuration options

Name Default Changeable Changelog
mail.add_x_header «0» PHP_INI_PERDIR
mail.log NULL PHP_INI_SYSTEM|PHP_INI_PERDIR
mail.force_extra_parameters NULL PHP_INI_SYSTEM|PHP_INI_PERDIR
SMTP «localhost» PHP_INI_ALL
smtp_port «25» PHP_INI_ALL
sendmail_from NULL PHP_INI_ALL
sendmail_path «/usr/sbin/sendmail -t -i» PHP_INI_SYSTEM

For further details and definitions of the PHP_INI_* modes, see the Where a configuration setting may be set.

Here’s a short explanation of the configuration directives.

Add X-PHP-Originating-Script that will include UID of the script followed by the filename.

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.

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.

Used under Windows only: host name or IP address of the SMTP server PHP should use for mail sent with the mail() function.

Used under Windows only: Number of the port to connect to the server specified with the SMTP setting when sending mail with mail() ; defaults to 25.

Which «From:» mail address should be used in mail sent directly via SMTP (Windows only). This directive also sets the «Return-Path:» header.

Where the sendmail program can be found, usually /usr/sbin/sendmail or /usr/lib/sendmail . configure does an honest attempt of locating this one for you and set a default, but if it fails, you can set it here.

Systems not using sendmail should set this directive to the sendmail wrapper/replacement their mail system offers, if any. For example, » Qmail users can normally set it to /var/qmail/bin/sendmail or /var/qmail/bin/qmail-inject .

qmail-inject does not require any option to process mail correctly.

This directive works also under Windows. If set, smtp , smtp_port and sendmail_from are ignored and the specified command is executed.

User Contributed Notes 7 notes

On Ubuntu 13.04, not sure of the other Distros.

If you simply uncomment the default:

sendmail_path = «sendmail -t -i»

Your mail() functions will all fail. This is because, you should place the FULL PATH (i.e. /usr/sbin/sendmail -t -i )

The documentation states PHP tries it’s best to find the correct sendmail path, but it clearly failed for me.

So, always enter in the FULLPATH to sendmail or you may get unexpected failing results.

As a secondary note: Those that just want to ENFORCE the -f parameter, you can do so in php.ini using:

You can leave the sendmail path commented out, it will still use the defaults (under UNIX -t -i options which if you look them up are very important to have set).

But, now there is no way to change this, even with the 5th argument of the mail() function. -f is important, because if NOT set, will be set to which ever user the PHP script is running under, and you may not want that.

Also, -f sets the Return-Path: header which is used as the Bounce address, if errors occur, so you can process them. You you can not set Return-Path: in mail() headers for some reason. you could before. Now you have to use the -f option.

If anyone gets this cryptic error message in the PHP error logs:
«sh: -t: command not found»
after upgrading from PHP 5.4, this may be the solution for you.

I upgraded PHP from 5.4 to 5.6 and all our mail() functionality suddenly broke, with no useful error logging.

If this is you, and you’ve been using ini_set() to set the «sendmail_path» then note that even though it’s apparently not mentioned in the upgrade documentation — or anywhere else I could find on php.net (or a dozen forums) — you’ll now need to go set the sendmail_path in your php.ini file; it is now ignored if you use ini_set() to specify a path to the sendmail binary on the fly.

So, just specify «sendmail_path» in php.ini instead. That’s all there is to it — that fixed all the mail() functionality for us.

Hope this little note saves someone else as much time as I spent troubleshooting and researching. Cheers!

The documentation should be made clear that sendmail does NOT default to -t -i when using just /usr/sbin/sendmail. You literally need to specify the options.

I know this might seem like a no-brainer but I wasted hours trying to get mail() to work only to discover that the sendmail program is NOT passed -t and -i by default as stipulated in the documentation.

It is worth reiterating that, as stated above, sendmail_path also works for Windows, overriding other Windows SMTP settings.

The comment in php.ini, “For Unix only”, does not make that clear.

This makes it relatively easy to substitute a fake sendmail program or even a shell script/batch file to save mail to a text file.

I use this technique when teaching or testing in PHP.

For linux you can over-ride the default «From» for the outgoing emails by including in php.ini this line:

sendmail_path = «/usr/sbin/sendmail -t -i -f fromMe@blah.com»

The path should work for most linux installations.

setting return path:

Return-path header does not work because it is not part of smtp.

on *nix -f may be set on the mail command
alternatively
some MTAs accept mbox-style «From » header on the first header line
note: no colon after «From» , must be the first header line
or you may be able to re-configure you MTA to interpret return-path headers

-f is the most reliable method but it may mean that you can’t set any other command-line option due to shell escaping problems.

also note that email formatting requirements differ between windows and everything else. sendmail expects only \n line-endings

On Darwin OS such as OSX (current one: 10.8.3) you need to add a specific command and option to the sendmail_path constant if you have downloaded and installed a mamp with a stack.

Indeed you can see the required libraries for PHP, Apache, MySQL in «common/lib» folder. The problem is when you run an external command using these libraries, for example «sendmail». It could be a problem if it gets the stack libraries and not the system ones (different versions, etc).

The «env -i» command clean the Stack environment variables and run «sendmail» with the system libraries.

Источник

Оцените статью
toolgir.ru
Adblock
detector