0

I'm trying to send emails from my localhost, but I'm running across an issue that keeps coming up. I found this answer which explained how to set up XAMPP to send email, and the emails are sent, but when I try changing the From header, nothing happens. The email gets sent, but it's sent from my personal email.

I tried removing both the sendmail_from in php.ini and force_sender in sendmail.ini, but neither worked. I tried adding the -f parameter to the mail function, and it didn't work. I've even tried restarting XAMPP several times, but still nothing. Is there something I've overlooked or is there no way to do this?

PHP

<?php
  $headers = "From: Joe Smith <[email protected]>" . "\r\n";
  mail("[email protected]", "This is a test message", "Yup, it's a test message all right.", $headers, "-f [email protected]");
?>

php.ini

[mail function]
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = 
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

sendmail.ini

[sendmail]

smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=mypersonalpassword
yaakov
  • 4,568
  • 4
  • 27
  • 51

2 Answers2

0

It is because you are using Google's SMTP servers and they don't allow changing the 'From' header.

This was answered here: How to change from-address when using gmail smtp server

Chase Taylor
  • 104
  • 8
0

I just did a project similar to this. Depending on your needs, you can use PHPMailer to change your "reply to" address. Although it's not the same as changing the from address, it achieves a similar goal, is easy to use, and has a good community. Also, it works perfectly with Google Mail.

ilovecoffee
  • 66
  • 1
  • 3