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 <joe@joesmith.com>" . "\r\n";
  mail("recipient@gmail.com", "This is a test message", "Yup, it's a test message all right.", $headers, "-f joe@joesmith.com");
?>

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
auth_username=mypersonalemail@gmail.com
auth_password=mypersonalpassword
yaakov
  • 4,568
  • 4
  • 27
  • 51
  • GMail possibly doesn't allow changing the `From` header and replaces it with a different one – rollstuhlfahrer Jan 21 '18 at 01:33
  • Your sendmail_from doesn't have anything. Have you tried setting it? Plus, what's the OS? You can also set it in the `sendmail_path` as `sendmail_path = /usr/sbin/sendmail -t -i -F"Full Name" -f'emailaddress@example.com'`. – Funk Forty Niner Jan 21 '18 at 01:52

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