PHPMailer for SMTP将邮件发送到收件箱,但邮件地址无效

时间:2015-01-12 04:25:51

标签: php email phpmailer

需要帮助!!! 我在我当前的项目中使用php邮件程序。它成功运行,在成功发送邮件到另一端后,它说来自smtp服务器帐户的邮件不是来自我在这里使用的$ -

$to ="muradautorun@gmail.com";
$from ="tanvir_cse0906@yahoo.com";

我的smtp服务器代码在这里..

$mail->Host = 'smtp.gmail.com';
$mail->Port = 465; 


$mail->Username = "muradautorun"; 
$mail->Password = "";  //my passsword here

这是我的完整代码 -     

    $to ="muradautorun@gmail.com";
    $from ="tanvir_cse0906@yahoo.com";
    $from_name="S.M. Murad Hasan Tanvir";
    $subject="A sending mail code";
    $body ="This is a sending email code, the file attach here is about the coding.";

    //here i use gmail as a smtp server
    $mail = new PHPMailer();  // create a new object
    $mail->IsSMTP(); // enable SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;  // authentication enabled
    $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
    $mail->Host = 'smtp.gmail.com';
    $mail->Port = 465; 


    $mail->Username = "muradautorun"; 
    $mail->Password = "";  //my passsword here


    $mail->SetFrom($from, $from_name);
    $mail->addAttachment('emailSend.php');         // Add attachment(just the file url)
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->AddAddress($to);


    if(!$mail->Send()) {
        echo 'Mail error: '.$mail->ErrorInfo; 
    } 
    else {
        echo 'Message sent!';
    }
?>

我做错了,我无法找到,请帮帮我... 提前谢谢。

1 个答案:

答案 0 :(得分:0)

您需要允许发送邮件为" tanvir_cse0906@yahoo.com"在你的" muradautorun"首先是gmail帐户。

您可以按照以下步骤执行此操作:

  1. 使用" muradautorun"
  2. 登录
  3. 点击右上角的齿轮,然后选择"设置"
  4. 点击"帐户和导入"标签
  5. 点击链接"添加您拥有的另一个电子邮件地址"在"发送邮件为"部分,并按照说明进行操作。