Gmail SMTP邮件发送:没有错误,邮件未发送

时间:2014-07-18 03:36:12

标签: php email smtp gmail

所以本周早些时候我问的是如何使用像hMailServer这样的SMTP发送邮件,不知何故我开始在本地工作(但它突然需要密码和用户名)。  现在我试图通过gmail的smtp服务器发送邮件,但我似乎无法使它工作。没有错误消息,并且没有发送邮件。我可以知道我做错了什么吗?

CODE1 - localhost SMTP 正常工作

if ($ways=="cashchequesc"){
$_SESSION['youdont'] = "0";
$mail->IsSMTP();                         
$mail->Host     = "localhost";           
$mail->SMTPAuth   = true;                
$mail->Port       = 25;                 
$mail->Username   = "admin@127.0.0.1.";  
$mail->Password   = "password123";         
$mail->From     = ("pie-company@gmail.com");
$mail->FromName = ("Pie D-licious");
$mail->AddAddress("pielover2014@gmail.com","Valued Customer");
$mail->Subject  = $myusername . "'s Purchases of ". $_SESSION['amount'] ." of XXXX.";
$mail->Body     = $userIName . " owner/user of account " . $myusername ." has purchased     " . $_SESSION['amount'] . " (quantity) of  X item(s). Total amount of S$" .      
$ _SESSION["payamount"] . ". Payment will be made through Cash/Cheque on Collection";
$mail->WordWrap = 70;

if(!$mail->Send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
}

代码2 - Gmail SMTP(无效)

else if ($ways=="netssc"){
$_SESSION['youdont'] = "0";  
$mail->IsSMTP();                         
$mail->Host     = "smtp.gmail.com";            
$mail->SMTPAuth   = true;                
$mail->Port       = 465;                 
$mail->Username   = "pie-company@gmail.com";  
$mail->Password   = "ilovebigpie-chipsdontlie19472013";        
$mail->From     = ("buymy.pie@gmail.com");
$mail->FromName = ("Pie D-licious");
$mail->AddAddress("pielover2013@gmail.com","Valued Customer");
$mail->Subject  = $myusername . "'s Purchases of ". $_SESSION['amount'] ." of XXXX.";
$mail->Body     = $userIName . " owner/user of account " . $myusername ." has purchased " . $_SESSION['amount'] . " (quantity) of  X item(s). Total amount of S$" .  
$_SESSION["payamount"] . ". Payment will be made through NETS/Bank Transfer.";
$mail->WordWrap = 70;

 if(!$mail->Send()) {
  echo 'Message was not sent.';
  echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
  echo 'Message has been sent.';
} 

0 个答案:

没有答案