Raj*_*kar 19 html php email phpmailer
当我试图通过PHPMailer发送邮件时,我收到此错误消息.我的代码如下:
<?
require("phpmailer/class.phpmailer.php"); // First we require the PHPMailer libary in our script
$mail = new PHPMailer(); // Next we create a new object of the PHPMailer called $mail
$mail->From = "rajasekar.kcet@gmail.com";
$mail->FromName = "Rajasekar";
$mail->AddAddress("rajasekar.kcet@gmail.com"); // This is the adress to witch the email has to be send.
$mail->Subject = "First PHP Email message"; // This is the subject of the email message.
$mail->Body = "Hi! \n\n This is my first e-mail sent through PHP."; // This is the actual email message
if(!$mail->Send()) // Now we send the email and check if it was send or not.
{
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
}
else
{
echo 'Message has been sent.';
}
?>
Run Code Online (Sandbox Code Playgroud)
Mic*_*aev 41
在Ubuntu(至少12.04)中,默认情况下似乎没有安装sendmail.您必须使用该命令安装它
sudo apt-get install sendmail-bin
您可能还需要为其配置适当的权限,如上所述.
ari*_*rik 12
我使用了这行代码
if($phpMailer->Send()){
echo 'Sent.<br/>';
}else{
echo 'Not sent: <pre>'.print_r(error_get_last(), true).'</pre>';
}
Run Code Online (Sandbox Code Playgroud)
找出问题所在.事实证明,我在安全模式下运行,并且在第770行或其他内容中,第五个参数$params被赋予mail(),在安全模式下运行时不支持.我只是简单地说出来了,瞧,它有效:
$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header/*, $params*/);
Run Code Online (Sandbox Code Playgroud)
它在MailSendPHPMailer 的函数内.
我刚刚遇到这个问题,并在我的apache错误日志中发现sendmail没有安装,安装后它全部正常工作!
root@web1:~$ tail /var/log/apache2/error.log
sh: 1: /usr/sbin/sendmail: not found
Run Code Online (Sandbox Code Playgroud)
确保您还包含 phpmailer 附带的 smtp 类:
// for mailing
require("phpmailer/class.phpmailer.php");
require("phpmailer/class.smtp.php");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
123226 次 |
| 最近记录: |