简体   繁体   English

通过PHP发送邮件时出错

[英]Error in sending mail through PHP

Here is a sample code to send email using PHPMailer 这是使用PHPMailer发送电子邮件的示例代码

<? require('./PHPMailer/PHPMailerAutoload.php');
$mail=new PHPMailer();
$mail->CharSet = 'UTF-8';

$body = 'This is the message';

$mail->IsSMTP();
$mail->Host       = 'smtp.gmail.com';

$mail->SMTPSecure = 'ssl';
$mail->Port       = 587;
$mail->SMTPDebug  = 2;
$mail->SMTPAuth   = true;

$mail->Username   = 'tanishq@gmail.com';
$mail->Password   = 'xyz';

$mail->SetFrom('tanishq@gmail.com', $name);
$mail->Subject    = 'subject';
$mail->MsgHTML($body);

$mail->AddAddress('rohit@gmail.com', 'title1');
$mail->AddAddress('mark@gmail.com', 'title2'); 


$mail->send();
?>

[UPDATED] and I am getting this weird error [更新],我得到这个奇怪的错误

2017-05-08 14:37:36 SMTP ERROR: Failed to connect to server: (0) 2017-05-08 14:37:36 SMTP connect() failed. 2017-05-08 14:37:36 SMTP错误:无法连接到服务器:(0)2017-05-08 14:37:36 SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting https://github.com/PHPMailer/PHPMailer/wiki/疑难解答

PS- I have also tried most of the solutions given on this site however am not getting success through that so i would appreciate if you can help me 附言:我也尝试了该网站上提供的大多数解决方案,但是并没有获得成功,因此,如果您能帮助我,我将不胜感激

$mailer->SMTPSecure = 'ssl'; 

should be 应该

$mail->SMTPSecure = 'ssl';

I think? 我认为?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM