Naruto
Naruto

Reputation: 6668

PHP Mail Headers Problem

I'm creating a simple PHP mail function. I have a small problem with its header. I'm trying to set the senders name to be the clients website, and when I use the following code:

$headers = "From: Websites' Name";
$headers .= "\nMIME-Version: 1.0\n"."Content-Type:  multipart/mixed;\n"." boundary=\"{$mime_boundary}\"";
$headers .= "Reply-To:  $email <$email>\n";
$headers .= "X-Sender:  $email <$email>\n";
$headers .= "X-Priority: 1\n";

I receive the E-mail and the sender would be "Websites' [email protected]". What I want is, to get rid of the "@h184905.safesecureweb.com" I only want the "Websites' Name" to appear ... Can anyone help me with that ???

Thanks

Upvotes: 0

Views: 1534

Answers (4)

Gumbo
Gumbo

Reputation: 655129

As already mentioned, you need to provide a valid mailbox in the From field. You can use imap_rfc822_write_address for that:

$headers = array(
    "From: ".imap_rfc822_write_address("info", "example.com", "Website's Name"),
    "MIME-Version: 1.0",
    "Content-Type: multipart/mixed; boundary=\"{$mime_boundary}\"",
    "Reply-To: ".imap_rfc822_write_address("info", "example.com", "Website's Name"),
    "X-Sender: ".imap_rfc822_write_address("info", "example.com", "Website's Name"),
    "X-Priority: 1"
);
$headers = implode("\r\n", $headers);

Upvotes: 0

Pekka
Pekka

Reputation: 449385

This is not possible. An E-Mail needs a valid from address.

The best you can do is what you already do in the other headers:

$headers = "From: \"Websites' Name\" <[email protected]>";

(insert your valid E-Mail [must be on the same server] for the example address)

I am assuming the Websites' is an example only - you may need to escape the quote character otherwise.

Upvotes: 2

Piskvor left the building
Piskvor left the building

Reputation: 92752

You need to set a valid From header - that is, a valid e-mail address. You can do this:

From: "Websites' Displayed Name" <[email protected]>

Note that if you have a space in the displayed name, you need to enclose it in double quotes, (and for non-ASCII characters (e.g. "ščřž"), you'll need to use quoted-pritable or base64).

Upvotes: 2

Nicky
Nicky

Reputation: 11

Maybe take a look at the mail() function at php.net

http://php.net/manual/en/function.mail.php

Upvotes: -1

Related Questions