Php注册电子邮件验证

时间:2016-06-28 09:22:19

标签: php email verification

我已经为我的网站整理了一个注册表格,该表格将使用电子邮件验证。我想选择一个默认邮箱来发送外发电子邮件。如何指定我的网站主机上的哪个邮箱将发送外发电子邮件?

if($result2){
    $to = $email;
    $subject = "Immo Registration Confirmation - $username";
    $header = "Immo: Confirmation from Immo";
    $message = "Thank you for registering at Immo Please click the link below to verify and activate your account. <br>";
    $message .= "http://www.test.com/confirm.php?passkey=$confirmcode";

    $sentmail = mail($to,$subject,$message,$header);

    if($sentmail)
    {
    echo "Your Confirmation link Has Been Sent To Your Email Address.";
    }
    else
    {
    echo "Cannot send Confirmation link to your e-mail address";
    }
}

电子邮件系统正在运行,我已对其进行了测试,但它来自的电子邮件地址是随机垃圾邮件,我想指定一个邮箱进行注册。如何实现这一目标?

2 个答案:

答案 0 :(得分:2)

您需要设置&#39;来自&#39;标题正确。以下内容来自文档http://php.net/manual/en/function.mail.php

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

答案 1 :(得分:1)

您可以通过将此邮件添加到$ he​​ader变量来定义发件人电子邮件。

$header .= 'From: from@mail.com \r\n';