如何使用php从xampp发送匿名电子邮件
I am trying to set my localhost to send email from xampp using PHP. how to do it so that I will be able to send email with any name to a valid email id.for example I should be able to send email from address mymail@rajkumar.com.
我正在尝试将我的localhost设置为使用PHP从xampp发送电子邮件。 如何做到这一点,以便我能够将任何名称的电子邮件发送到有效的电子邮件ID。例如,我应该能够从地址mymail@rajkumar.com发送电子邮件。 p> div>
You would be using PHP's mail
function:
http://php.net/manual/en/function.mail.php
The documentation says:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
The from address on an email is included in the $additional_headers. Look at this example below (also from PHP.net):
<?php
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "
" .
'Reply-To: webmaster@example.com' . "
" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
EDIT (elaborating spam notice):
Anyone can use mail headers to send an email from any address. For example, I can send an email to you and make it look like the sender is urgent@ups.com
. This email could contain some malicious files or a link to a phishing site. When you use your localhost XAMPP server to send mail from mymail@rajkumar.com
many email clients will try to verify that the mail indeed originated from rajkumar.com
. Since it originated from whatever the IP address of your localhost server is and not the domain you claimed to be sending from, it most likely will be marked as spam.