问题
I have used a PHP code for Mailing using a SMTP HOST as given below:
ini_set('SMTP','myserver');
ini_set('smtp_port',25);
$to = $email;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: NO-REPLY<no-reply@mydomain.com>" . "\r\n";
$subject = "Confirmation For Request";
$message = '<html>
<body>
<p>Hi '.$firstname.' '.$lastname.'</p>
<p>
We recieved below details from you. Please use given Request/Ticket ID for future follow up:
</p>
<p>
Your Request/Ticket ID: <b>'.$ticketID.'</b>
</p>
<p>
Thanks,<br>
'.$team.' Team.
</p>
</body>
</html>';
mail( $to, $subject, $message, $headers );
Now When i execute the code in Windows Localhost.. I am succcesfully recieving the mail whereas, If I deply the same code on my Linux setup, I do not recieve anymail, though the mail() function returns true in linux machine as well....
On looking into the phpinfo for both windows localhost and Linux server, for mail parameters I found a single difference,
In Windows I found sendmail_path == "No Value", whereas on linux server it says, "usr/sbin/sendmail -t -i"
Could some one help me to resolve this issue?
NOTE: In windows, its a WAMP setup, whereas Linux is a Dedicated server...
回答1:
If you're looking to your php.ini
there is a short description that
ini_set('SMTP','myserver');
ini_set('smtp_port',25);
This both values are only for Windows. So if you want to send mails over SMTP on linux you have to install postfix for example and build a relay.
https://www.linode.com/docs/email/postfix/postfix-smtp-debian7
Or what is really much easier use a lib that can send SMTP mail over socket or curl like Swiftmailer.
http://swiftmailer.org/docs/sending.html
Thats much easier and its working.
回答2:
I have had a look at this before and in PHP.ini there are two keys sendmail_from
http://php.net/sendmail-from (For Win32) and sendmail_path
http://php.net/sendmail-path (For Unix) on a wamp or similar setup for linux the default of this key is me@localhost which when on an actual mail server it should reject that email address as a user as they don't exist on the server.
Try adding something like...
ini_set('sendmail_from','admin@example.co.uk')
来源:https://stackoverflow.com/questions/18717119/php-mail-function-with-runtime-ini-set-for-smtp-and-smtp-port-not-working-o