[英]Send an email using php
I'm trying to send an email using php, but when I try it on browser I get error: 我正在尝试使用php发送电子邮件,但是当我在浏览器中尝试发送电子邮件时,出现错误:
"The server failed to send the message. Please try again later."
“服务器无法发送消息。请稍后再试。”
Here is my php file 这是我的PHP文件
<?php
if( isset($_GET['n']) && isset($_GET['e']) && isset($_GET['m']) ){
$n = $_GET['n']; // HINT: use preg_replace() to filter the data
$e = $_GET['e'];
$m = nl2br($_GET['m']);
$to = "amal.soltni@esprit.tn";
$from = $e;
$subject = 'Contact Form Message';
$message = '<b>Name:</b> '.$n.' <br><b>Email:</b> '.$e.' <p>'.$m.'</p>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
if( mail($to, $subject, $message, $headers) ){
echo "success";
} else {
echo "The server failed to send the message. Please try again later.";
}
}
?>
Try This one to send the mail and use live server to execute this code, don't use localhost to send the mail 尝试使用此命令发送邮件并使用实时服务器执行此代码,请勿使用localhost发送邮件
<?php
if( isset($_GET['n']) && isset($_GET['e']) && isset($_GET['m']) ){
$n = $_GET['n'];
$e = $_GET['e'];
$m = nl2br($_GET['m']);
$to = "amal.soltni@esprit.tn";
$from = $e;
$subject = "My subject";
$message = '<b>Name:</b> '.$n.' <br><b>Email:</b> '.$e.' <p>'.$m.'</p>';;
$headers = 'From: .$from.' . '\r\n' .
$send = mail($to,$subject,$message,$headers);
}else {
echo "The server failed to send the message. Please try again later.";
}
?>
Please use this following code. 请使用以下代码。
<?php
if (isset($_POST["submit"]))
{
$n = $_POST['n'];
$e = $_POST['e'];
$m = $_POST['m'];
$to = "amal.soltni@esprit.tn";
$from = $e;
$subject = 'Contact Form Message';
$message = '<b>Name:</b> '.$n.' <br><b>Email:</b> '.$e.' <p>'.$m.'</p>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
if( mail($to, $subject, $message, $headers) ){
echo "success";
} else {
echo "The server failed to send the message. Please try again later.";
}
}
?>
<form method="post" >
<input type="text" name="n" placeholder="Name"><br>
<input type="email" name="e" placeholder="Email"><br>
<textarea col="10" rows="5" name="m" placeholder="Message"></textarea><br>
<input type="submit" name="submit">
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.