2012-12-14 82 views
2

我一直在尝试为我的网站做一个电子邮件确认。人们可以注册没有问题,并且所有内容都注册到数据库中,但不会发送电子邮件。我正常使用它,它给了我关于SMTP服务器的一些错误,所以有人说我应该尝试SurgeMailer。我下载了它,现在电子邮件实际上说他们发送了,但电子邮件从未收到它们。任何帮助将是伟大的!下面是发送电子邮件的代码。通过php发送邮件不工作

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

$subject="Newgenstudios Account Confirmation"; 

/*From*/ 
$header="From:Newgenstudios <[email protected]>"; 

/* 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"; 
} 
?> 
+1

检查您的日志文件是否有错误。 PHP的'mail()'函数并不保证邮件发送,只是它被接受发送。 – j08691

+0

btw为了发送HTML电子邮件,您需要定义MIME-TYPE和Content-type。此页面底部的示例:http://www.w3schools.com/php/func_mail_mail.asp – christopher

+0

您不必包含MIME-TYPE和Content-Type。无论如何它会发送。 @ user1868065如果它是你的服务器,检查/ var/log/maillog,看看里面是否有错误。如果您无法访问服务器,可尝试使用SwiftMailer并使用IMAP等方式通过另一台邮件服务器进行连接。 – ChrisG

回答

0

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

2 - 写“从价值”为有效的电子邮件与你的域名,如:若步骤不起作用,请致电您的托管我猜邮件阻止他们()函数[email protected]

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: [email protected]' . "\n"; 

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

我其实只是尝试PHP邮件,它原来也是一个PHP邮件扩展名已关闭,并尝试使用Phpmailer风格,而且效果很好,谢谢你的帮助! – user1868065

0

我建议使用Gmail帐户发送电子邮件,这是为我设置的最快的一个。 (只是谷歌'发送PHP的Gmail邮件')。另外,不要忘记检查垃圾邮件文件夹。