0

I am facing this problem where the mail is getting sent as a different email rather than the one specified.

                    $from_name = 'send';
                    $from = 'send@test.com';
                    $to = 'receive@test.com';
                    $to_name = 'receive';
                    $also_to = 'cc@test.com';
                    $also_to_name = 'cc';
                    $message = 'Dear receive Thank you for the booking';
                    $message .= '<br><br>'.$homepage;
                    $mail = new PHPMailer();
                    $mail->SMTPDebug  = 0;
                    $mail->IsSMTP();    
                    $mail->Port = 465;
                    $mail->Host = "ssl://smtp.gmail.com";
                    $mail->SMTPAuth = true;
                    $mail->Username = 'send1@test.com';
                    $mail->Password = ******;

                    $mail->SetFrom($from,$from_name );
                    $mail->AddReplyTo($from,$from_name );
                    $mail->Subject  = 'Booking Details';
                    $mail->MsgHTML($message);
                    $mail->AddAddress($to,$to_name);
                    $mail->AddCC($also_to,$also_to_name);

When I sent it using this code the mail goes with name as 'send' but not the 'send@test.com' email address it gets sent from "send -> send1@test.com" rather than send -> send@test.com. Above I have mentioned the smtp details that i have used. Also when i change:

                    $mail->Username = 'send@test.com';
                    $mail->Password = ******;

The mail does not go through to any email address. I hope this is clear enough for you guys and I would appreciate any help. Thank you

DEV
  • 647
  • 4
  • 19
  • 31

3 Answers3

1

$mail->Username = send1@test.com;

this need to be in quotes like :

$mail->Username = "send1@test.com";

Check whether this resolves you issue ?

If not try setting debug to true $mail->SMTPDebug = 1;

and see what's being actually sent to gmail server

By default gmail will use the account's email address

Ref : How to change from-address when using gmail smtp server

Community
  • 1
  • 1
Akhil Thayyil
  • 9,263
  • 6
  • 34
  • 48
0

Look at this: http://phpmailer.worxware.com/index.php?pg=properties

$From public root@localhost Sets the From email address for the message

and

$FromName public Root User Sets the From name of the message

So you want specifically add the following:

$mail->From = $from;
$mail->FromName= $from_name;
Amarnasan
  • 14,939
  • 5
  • 33
  • 37
  • so changing this in the class.phpmailer.php to the above will rectify it? that would mean i have to include the filename in phpmailer file too right? What if i change those values in the php mailer to the name and id i require? – DEV Nov 04 '15 at 09:02
  • I don't know the name of the script that you show above. Just add those two lines in the same place you add the rest of the parameters and give it a try. – Amarnasan Nov 04 '15 at 09:05
  • OK I will try that. What about the $mail->SetFrom() function? is that still required or do i include those values inside the $mail->SetFrom function? – DEV Nov 04 '15 at 09:09
  • I tried that the from is still showing the same email id in smtp username – DEV Nov 04 '15 at 09:45
-1

You have to call setFrom method to set the sender's mail address and name:

$mail->SetFrom('send@test.com', 'Your Name');
mario.van.zadel
  • 2,919
  • 14
  • 23
  • $mail->SetFrom($from,$from_name ); I have included that in the above code adding the variables. Giving the actual values will help? – DEV Nov 04 '15 at 08:50