user1480951
user1480951

Reputation: 143

Setting from address in phpmailer webforms

I am using the following code to send emails using phpmailer 6:


$mail->isSMTP();
$mail->Host = 'myhost';
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = '[email protected]';
$mail->Password = 'password';
$mail->Port = '587';

$mail->ContentType = 'text/plain'; 
$mail->IsHTML(false);
$mail->setFrom('[email protected]');
$mail->addReplyTo($_POST['email'], $_POST['name']);

$mail->addAddress($to);
$mail->Subject = $_POST['subject'];
$mail->Body    = "...";

$mail->send();

The email sends successfully to our company, however it always says it is from [email protected], which makes it hard for staff to find specific emails in their inbox. In the form, the user provides their name and email so ideally I'd like it to appear in Outlook as being sent from John Doe ([email protected]) rather than [email protected].

In old versions of webforms I use to do this by setting the from address however now that doesn't seem to be possible because it's considered spoofing.

Is there a way to accomplish this?

Upvotes: 0

Views: 92

Answers (1)

ComputerLocus
ComputerLocus

Reputation: 3618

Simply add in the name as the second parameter in your setFrom. See the example below:

$mail->setFrom('[email protected]', 'Darth Vader');

It'll then appear as you want it!

Upvotes: 1

Related Questions