1

When I run this script to send an email, the email is being sent from serveradmin@myhosting. They say that the script isn't configured correctly.

I've changed the domain names and info shown below before posting here.

Is there really a problem with the scrip? The email sends, everything is fine. It takes a bit long...don't know why, the only problem is it doesn't send from the domain I specified.

    $to = $_POST['fes-email'];
    $subject = 'TEST';

    $body = 'TEST TEST';

    $headers =  'From: NAME \(Info\) <name@domain.tld>' . "\r\n" .
                'Reply-To: name@domain.tld' . "\r\n" .
                'Return-Path: name@domain.tld' . "\r\n" .

                'X-Priority: 1' . "\r\n" .
                'MIME-Version: 1.0' . "\r\n" .


    mail($to, $subject, $body, $headers);
Nikk
  • 7,384
  • 8
  • 44
  • 90
  • 1
    Does it work if you remove the backslashes before the parentheses? I don't think it's needed. – Barmar Feb 12 '15 at 01:51
  • It does. Just doesn't display whatever is written inside the parentheses. I am using the backslashes to escape the parentheses. Like you would use backslashes to escape double quotes inside double quotes, or single inside single. – Nikk Feb 12 '15 at 01:52

2 Answers2

0

Try using quotes instead of escaping the parentheses:

$headers = 'From: "NAME (Info)" <name@domain.tld>' . "\r\n" .

You should remove the Return-path: header. This header is always recreated by the receiving server, using the envelope information sent via SMTP.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • The name appeared like is should without having to escape. However, when I looked at the headers `Return-Path: `, and also the envelope is signed by the same address. I am on media temple if that makes a difference, shouldn't. – Nikk Feb 12 '15 at 01:59
  • `Return-path` is not settable by client applications. The receiving server creates that header by using the envelope sender address. – Barmar Feb 12 '15 at 02:09
  • First time I'm playing with php email...going off what the hosting said. This is a [link](http://stackoverflow.com/questions/10622808/how-to-change-the-return-path-header-on-email-notification) they suggested. – Nikk Feb 12 '15 at 02:14
  • I think if you need to customize the envelope sender, that will have to be done in the PHP configuration. I'm not sure where. – Barmar Feb 12 '15 at 02:23
  • Will something like this do anything `mail('to@blah.com','subject!','body!','From: from@blah.com','-f from@blah.com');`? [LINK](http://stackoverflow.com/questions/179014/how-to-change-envelope-from-address-using-php-mail) – Nikk Feb 12 '15 at 02:29
  • `-f` is used to set the `From:` address, not the envelope sender. – Barmar Feb 12 '15 at 02:34
  • Maybe adding a `Sender:` line to `$headers` will work, but I doubt it. I suspect you need to do something in `php.ini`. – Barmar Feb 12 '15 at 02:34
  • Maybe something in http://php.net/manual/en/mail.configuration.php will be helpful. – Barmar Feb 12 '15 at 02:36
  • Thanks...I'll check with the hosting again. As for this answer, I like the quotes instead of having to escape. So thanks. :) – Nikk Feb 12 '15 at 02:38
0

Have you tried putting just <name@domain.tld> in the headers for From?

Fata1Err0r
  • 836
  • 1
  • 6
  • 14