PHPmailer:从电子邮件更改用户名

时间:2016-07-01 13:00:02

标签: php phpmailer core

  

使用phpmailer发送邮件。但它显示我的用户名(电子邮件)。我必须显示发件人电子邮件ID。请给我解决方案。

     

接触submit.php

\uxxxx
  

发送电子邮件后,结果看起来像这样:

     

RESULT

<?php 
  require('phpmailer/class.phpmailer.php');
  require('phpmailer/class.smtp.php');

    $txtname = $_POST['txtname'];
    $txtemail = $_POST['txtemail'];
    $txtmobile = $_POST['txtmobile'];
    $txtmessage = $_POST['txtmessage'];
    $txtname = $_POST['txtname'];   

    $mail = new PHPMailer();
    $mail->IsSMTP();// enable SMTP
    $mail->SMTPDebug = 0;// debugging: 1 = errors and messages display after success message, 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->IsHTML(true);
    $mail->Username = "ashishaware2@gmail.com";
    $mail->Password = "Ashish2";
    $mail->Mailer   = "smtp";
    $mail->SetFrom("abcd@gmail.com",$txtname);      
    $mail->AddReplyTo($txtemail, $txtname);
    $mail->AddAddress("ashishaware2@gmail.com");
    $mail->Subject = "Test email using PHP mailer";
    $mail->WordWrap   = 80;
    $content =" <b> NAME :</b>  $txtname "."<br>"; 
    $content.=" <b> EMAIL :</b> $txtemail "."<br>";
    $content.=" <b> MOBILE :</b>$txtmobile "."<br>";
    $content.=" <b> MESSAGE :</b>$txtmessage "."<br>";
    $mail->MsgHTML($content);

    if(!$mail->Send()) 
    echo "Problem sending email.". $mail->ErrorInfo;
    else 
    echo "email sent.";


?>
  

我的预期结果是

    virat <ashishaware2@gmail.com>
    To ashishaware2@gmail.com
   Today at 18:13
   NAME : virat
   EMAIL : virat2830@gmail.com
  MOBILE :9850971456
    MESSAGE :hi 

1 个答案:

答案 0 :(得分:0)

如果您因垃圾邮件/安全性而通过Gmails SMTP发送邮件,Gmail将不允许您更改电子邮件中的FROM标头。

More information