Change email address that sends confirmation email (PHP)
I have a registration page on a site I'm working on. When the person registers for an account it sends an email to the registrants email address with a confirmation link to activate the persons account. The problem is that the "from" email address the registrant receives the email from is: myhostingaccountusername@myhostingprovider###.com
.
I want to be able to have the email be: no-reply@mydomain.com
.
I'm using PHP and Mysql along with html for the 开发者_JS百科site.
here is my code for sending the email.
// Send the email:
$body = "Thank you for registering at My site. To activate your account, please click on this link:\n\n";
$body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$abc";
mail($trimmed['email'], 'Registration Confirmation', $body, 'From: noreply@mysite.com');
How do I do this?
When sending the e-mail to your "registrant" you should set the headers of the mail function in PHP to contain "From" field
for example :
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: no-reply@example.com' . "\r\n" .
'Reply-To: me@example.com' . "\r\n";
mail($to, $subject, $message, $headers);
?>
Have you set the From:
header for the e-mail?
See http://php.net/manual/en/function.mail.php, example #2.
精彩评论