My ISP
account requires that I send a username & password for outbound SMTP
mail.
How do I get PHP
to use this when executing php.mail()?
The php.ini
file only contains entries for the server (SMTP= )
and From: (sendmail_from= )
.
My ISP
account requires that I send a username & password for outbound SMTP
mail.
How do I get PHP
to use this when executing php.mail()?
The php.ini
file only contains entries for the server (SMTP= )
and From: (sendmail_from= )
.
PHP mail()
command does not support authentication. Your options:
mail()
does support authentication if (a) sendmail is installed on the server and (b) authentication details are provided in the php.ini file. See answers below for details.
Commented
Apr 11, 2014 at 14:44
mail()
, not to PHPMailer
I apply following details on php.ini file. its works fine.
SMTP = smtp.example.com
smtp_port = 25
username = [email protected]
password = yourmailpassord
sendmail_from = [email protected]
These details are same as on outlook settings.
Warning: mail(): SMTP server response: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM
Use Fake sendmail for Windows to send mail.
sendmail
in C:\wamp\
.sendmail
folder: sendmail.exe
, libeay32.dll
, ssleay32.dll
and sendmail.ini
.C:\wamp\sendmail\sendmail.ini
:smtp_server=smtp.gmail.com smtp_port=465 [email protected] auth_password=your_password
The above will work against a Gmail account. And then configure php.ini:
sendmail_path = "C:\wamp\sendmail\sendmail.exe -t"
Now, restart Apache, and that is basically all you need to do.
smtp
configuration from your php.ini
file because that isn't really required if you already handle those values in your sendmail.ini
file. Also I was only able to get it to work if I use sendmail_path = "C:\Program Files (x86)\sendmail\sendmail.exe"
without the -t
parameter. If anyone is curious, I was using IIS on Windows 10.
PHP does have authentication on the mail-command for windows only!
The following is working for me on WAMPSERVER (windows, php 5.2.17)
php.ini
[mail function]
; For Win32 only.
SMTP = mail.yourserver.com
smtp_port = 25
auth_username = smtp-username
auth_password = smtp-password
sendmail_from = [email protected]
/etc/postfix/main.cf
to read:#Relay config
relayhost = smtp.server.net
smtp_use_tls=yes
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_sasl_security_options = noanonymous
/etc/postfix/sasl_passwd
, enter:smtp.server.net username:password
Type # /usr/sbin/postmap sasl_passwd
Then run: service postfix reload
Now PHP will run mail as usual with the sendmail -t -i
command and Postfix will intercept it and relay it to your SMTP server that you provided.
I prefer the PHPMailer tool as it doesn't require PEAR. But either way, you have a misunderstanding: you don't want a PHP-server-wide setting for the SMTP user and password. This should be a per-app (or per-page) setting. If you want to use the same account across different PHP pages, add it to some kind of settings.php file.
After working all day on this, I finally found a solution. Here's how I send from Windows XP with WAMP.
<?php $message = "test message body"; $result = mail('[email protected]', 'message subject', $message); echo "result: $result"; ?>
Reference:
These answers are outdated and deprecated. The actual best practice would be:
composer require phpmailer/phpmailer
As the next step, your sendmail.php file just requires the following:
# use namespace
use PHPMailer\PHPMailer\PHPMailer;
# require php mailer
require_once "../vendor/autoload.php";
//PHPMailer Object
$mail = new PHPMailer;
//From email address and name
$mail->From = "[email protected]";
$mail->FromName = "Full Name";
//To address and name
$mail->addAddress("[email protected]", "Recepient Name");
$mail->addAddress("[email protected]"); //Recipient name is optional
//Address to which recipient will reply
$mail->addReplyTo("[email protected]", "Reply");
//CC and BCC
$mail->addCC("[email protected]");
$mail->addBCC("[email protected]");
//Send HTML or Plain Text email
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
This can be configured however you like.
"SMTP = localhost",
"smtp_port = 25",
"; sendmail_path = ".
Credit: How to configure WAMP (localhost) to send email using Gmail?