发送电子邮件使用PHP代码
问题描述:
下面的代码是将电子邮件发送到下面的帐户,但是当我在服务器上运行它是没有行动发送电子邮件和代码是不是错误,感谢您的帮助。发送电子邮件使用PHP代码
<?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
答
尝试用这种
<?php
/* Setup your Subject and Message Body */
$subject='Testing php Email';
$body=' Put Your Text Message Here.';
/* Specify your SMTP Server, Port and Valid From Address */
ini_set("SMTP","mail.yourdomain.com");
ini_set("smtp_port","25");
ini_set("sendmail_from","[email protected]");
/* Additional Headers */
$headers = "Cc:Real CC Name <[email protected]>\r\n";
$headers .= "Bcc:Real BCC Name <[email protected]>\r\n";
/* Try to send message and respond if it sends or fails. */
if(mail ('ToPersonsName <[email protected]>', $subject, $body, $headers)){
echo "<h2>Your Message was sent!</h2>";
}
else{
echo "<font color='red'><h2>Your Message Was Not Sent!</h2></font>";
}
exit;
?>
答
$toEmail="your email";
$sub="your subject";
$to=$toEmail;
$subject=$sub;
$from="[email protected]";
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "From: <".$from.">\n";
$headers .= "X-Priority: 1\n";
$message='<div style=" width:700px; margin:0 auto; border:1px solid #e2e2e2; padding:20px;">
<h3>MYPROPICK Services:</h3>'.$msg.'</div>';
$message .= "<br/>Regards <br />MYPROPICK.COM";
if(mail($to, $subject, $message, $headers))
echo "Mail Sent Successfully";
else
echo "Mail is not sent please set your smtp setting";
你'smtp'配置不正确。 – 2013-03-16 04:27:29