我正在使用PHP mail
函数发送邮件,但我正在测试我的本地服务器邮件已发送但我的直播我无法发送邮件。你能帮我吗?
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "xxxxxxx@gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
答案 0 :(得分:1)
为什么在有codeigniter mail()
class时使用email
。
$this->load->library('email');
$this->email->from('your@example.com', 'Your Name');
$this->email->to('someone@example.com');
$this->email->cc('another@another-example.com');
$this->email->bcc('them@their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
使用mandrillapp
使用SMTP发送邮件,并为email
类添加凭据。
答案 1 :(得分:0)
将此用作html(测试)
<form action="#" method="post">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email"/>
<input type="text" name="phone" placeholder="phone" />
<input type="text" name="message" placeholder="message"/>
<input type="submit" name="submit"/>
</form>
PHP
if(isset($_POST[submit]))
{
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "p******@gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email ";
}
}
?>
答案 2 :(得分:0)
试试吧。它的工作
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'Reply-To: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'X-Mailer: PHP/' . phpversion();
$to = "xxxxxxx@gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}