0

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

4 Answers 4

2

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).

Sign up to request clarification or add additional context in comments.

Comments

2

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.

1 Comment

That will send a mail saying From: Websites' <[email protected]>; the displayed name must be quoted if it contains spaces; the mailer takes the first non-quoted (and non-encoded, in case of QP or base64) space to be the separator between display name and e-mail address.
0

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);

Comments

-1

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.