2

Mail is sent using phpmailer. But it shows my username in from(Email) . I have to show sender email id. Please give me solution.

contact-submit.php

<?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.";


?>

After email sent Result is look like this way :

RESULT

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

My expected Result is

virat <virat2830@gmail.com>
To ashishaware2@gmail.com
Today at 18:13
NAME : virat
EMAIL : virat2830@gmail.com
MOBILE :9850971456
MESSAGE :hi 
Ashish Aware
  • 169
  • 2
  • 15
  • `$mail->SetFrom($txtemail, $txtname);` should do it – MonkeyZeus Jul 01 '16 at 13:17
  • @Fred-ii- I think OP wants the email between the pac-mans `` of line #1 to not be his authentication email :/ – MonkeyZeus Jul 01 '16 at 13:18
  • I think the real issue here is that Gmail may not allow you to change the FROM headers in an email if you're sending via Gmails SMTP, due to spamming / security. – Jamie Bicknell Jul 01 '16 at 13:21
  • IMHO you shouldn't forge the From header. Place all relevant data in the message body. Use plain text, a consistent format for key value pairs and include the full date/time. Makes for easier automated data extraction. – Progrock Jul 01 '16 at 13:28
  • turn on this link https://www.google.com/settings/security/lesssecureapps it will work –  Jul 02 '16 at 05:21

1 Answers1

1

Gmail will not allow you to change the FROM headers in an email if you're sending via Gmails SMTP, due to spamming / security.

More information

Community
  • 1
  • 1
Jamie Bicknell
  • 2,306
  • 17
  • 35