通过PHP发送邮件不工作

时间:2012-12-14 00:01:52

标签: php smtp sendmail

我一直在努力为我的网站确认电子邮件。人们可以注册没有问题,一切都注册到数据库,但它不发送电子邮件。我正常试了,它给了我一些关于smtp服务器的错误,所以有人说我应该试试SurgeMailer。我下载了它,现在电子邮件实际上说他们已发送,但电子邮件从未收到它们。任何帮助都会很棒!下面是发送电子邮件的代码。

/*Send Email here*/
$to=$Email;

$subject="Newgenstudios Account Confirmation";

/*From*/
$header="From:Newgenstudios <noreply@newgenstudios.com>";

/* Your message */   /*Not Finished */
$message = "<h3>Welcome to the site ".ucfirst(strtolower($First_Name))."!</h3>
<p>To complete your account registration, you must activate your account. Click on the link below or paste it into the URL to activate your account.</p>
<p><a href='http://localhost/confirmation.php?passkey=$confirm_code'>Activate Now!</a </p>
<p>Once your account has been activated, you may log in at anytime using the information you supplied below:<br />
<strong>Email: </strong>$Email<br />
<strong>Password: </strong>$Password</p>
<p>Other Information:</p>
<strong>Name: </strong>$First_Name<br />
<strong>Phone: </strong>$Phone<br />
<p>Thank you for registering and see you on the site!</p>
<p>Did you not register? Then please disregard this message.</p>";

/* Send Email */
$sentmail = mail($to,$subject,$message,$header);
}

/*If not found*/
else {
echo "Not found your email in our database";
}

/* email succesfully sent */
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 :(得分:0)

1-尝试使用此邮件功能。

2-将“from value”写为与您的域名相关的有效电子邮件,例如:noreply@domain.com

3-如果步骤不起作用,请致电您的托管我猜邮件()功能被他们阻止。

function send_mail($to,$from,$subject,$msg){
        // message
        $message = '
        <html>
        <head>
          <title>Message</title>
        </head>
        <body dir="rtl">
        <p align="right">'
        . $msg .
        '</p>
        <br>

        </p>
        </body>
        </html>
        ';

        // To send HTML mail, the Content-type header must be set
        $headers  = 'MIME-Version: 1.0' . "\n";
        $headers .= 'Content-type: text/html; charset=utf-8' . "\n";

        // Additional heade rs
        $headers .= "From: ".$from . "\n";
        //$headers .= 'Bcc: info@domain.co.uk' . "\n";

        // Mail it
        return mail($to, '=?windows-1256?B?'.base64_encode($subject).'?=', $message, $headers);
    }

答案 1 :(得分:0)

我建议使用Gmail帐户发送电子邮件,这是我设置的最快的电子邮件。 (只是google'发送php gmail email')。另外,不要忘记查看垃圾邮件文件夹。