无法使用 PHP 发送邮件
Cannot send mail with PHP
我正在尝试使用以下代码通过 PHP 发送非常基本的邮件;
if (mail('mymail@gmail.com','Test mail','Testing mail function!'))
{
echo "Email was sent successfully!";
}
else
{
echo "Email was not sent!";
}
然而,输出总是'Email was not sent'。我使用 Xaamp 在我的机器上本地 运行 这个脚本。
我已经尝试为此研究解决方案,但我没有运气。这似乎与服务器配置有关。我尝试修改 php.ini 中的 sendmail,但仍然没有用。
非常感谢对此的任何帮助。
谢谢。
试试这个库:
您可以使用 smtp 而不是 sendmail。
XAMPP
中的邮件设置
$this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
$this->email->to('target@gmail.com'); //receiver mail
$this->email->subject('testing');
$this->email->message($message);
$this->email->send(); //sending mail
Configuration in sendmail.ini
路径c:\xampp\sendmail\sendmail.ini
配置
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com
in php.ini
路径c:\xampp\xampp\php\php.ini
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail_from = yourmail@gmail.com
您需要运行Mercury来模拟邮件服务器,这是一个Mercury教程:http://system66.blogspot.com.es/2010/01/how-to-send-mail-from-localhost-with.html
或者您可以使用 PHPMailer。
我正在尝试使用以下代码通过 PHP 发送非常基本的邮件;
if (mail('mymail@gmail.com','Test mail','Testing mail function!'))
{
echo "Email was sent successfully!";
}
else
{
echo "Email was not sent!";
}
然而,输出总是'Email was not sent'。我使用 Xaamp 在我的机器上本地 运行 这个脚本。
我已经尝试为此研究解决方案,但我没有运气。这似乎与服务器配置有关。我尝试修改 php.ini 中的 sendmail,但仍然没有用。
非常感谢对此的任何帮助。
谢谢。
试试这个库:
您可以使用 smtp 而不是 sendmail。
XAMPP
中的邮件设置$this->email->from('mygmail@gmail.com', 'myname');//your mail address and name
$this->email->to('target@gmail.com'); //receiver mail
$this->email->subject('testing');
$this->email->message($message);
$this->email->send(); //sending mail
Configuration in sendmail.ini
路径c:\xampp\sendmail\sendmail.ini
配置
[sendmail]
smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=myemail@gmail.com
auth_password=yourgmailpassword
force_sender=myemail@gmail.com
in php.ini
路径c:\xampp\xampp\php\php.ini
[mail function]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
sendmail_from = yourmail@gmail.com
您需要运行Mercury来模拟邮件服务器,这是一个Mercury教程:http://system66.blogspot.com.es/2010/01/how-to-send-mail-from-localhost-with.html
或者您可以使用 PHPMailer。