我正在尝试从我的网站发送电子邮件,我输入了正确的名称和电子邮件,但它没有发送它.. 你能帮帮我吗?
正在解析URL,并且html通过php很好地通信。 我把这行
echo $_POST["userName"].' y ';
//(to know if the name is getting to the php)
echo $_POST["userEmail"];
//(to know if the email is getting to the php)
并且它正常工作......也许错误发生在邮件行或其他事情上。
这是我的PHP代码
elseif ($page_name=='contact-post.html') {
if($_POST["userName"]!='' && $_POST["userEmail"]!=''){
echo $_POST["userName"].' y ';
//(to know if the name is getting to the php
echo $_POST["userEmail"];
//(to know if the email is getting to the php
$nombre = $_POST["userName"];
$correo = $_POST["userEmail"];
$asunto = "Mensaje de ".$nombre;
$mensaje = $_POST["userMsg"];
$correoMarsur = "mail@mail.com";
if(mail($correoMarsur,$asunto,$mensaje,$correo)){
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Mensaje enviado')
window.location.href='http://page.cl';
</SCRIPT>");
}
else{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Imposible enviar su mensaje')
window.location.href='http://page.cl';
</SCRIPT>");
}
}
else{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Ingrese Nombre y Correo')
window.location.href='http://page.cl';
</SCRIPT>");
}
}
这是我的HTML代码
<div class="form">
<!--<form method="post" action="/index.php/contact-post.html"> -->
<form method="post" action="../index.php/contact-post.html">
<input name="userName" id="userName" type="text" class="textbox" placeholder="Nombre*" />
<input name="userEmail" id="userEmail" type="text" class="textbox" placeholder="Email*" />
<div class="clear"> </div>
<div>
<textarea name="userMsg" id="userMsg" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Mensaje* ';}">Mensaje*</textarea>
</div>
<div class="submit">
<input type="submit" value="Enviar " />
</div>
</form>
</div>
邮件布尔值返回false,我该如何解决?
答案 0 :(得分:1)
您已将用户电子邮件放入mail()
函数的additional_headers参数槽中,这就是它返回false的原因。
这是您必须填写的参数:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
例如:
mail($correoMarsur,$asunto,$mensaje);
这应该有效,除非你的变量中有奇怪的数据。
答案 1 :(得分:0)
//SEND MAIL FUNCTION
function sendMail($to, $subject, $body, $headers)
{
if (mail($to, $subject, $body, $headers)) {
$returnMessage = "Success";
}
else {
$returnMessage = "Failed";
}
return $returnMessage;
}
//SET YOUR POST VARIABLES HERE
$name = ($_POST['userName']);
$email = ($_POST['userEmail']);
//SET YOUR EMAIL DETAILS HERE, HOWEVER THIS CAN BE PASSED IN FROM ELSEWHERE, HENSE THE FUNCTION
$to = "mail@mail.com";
$subject = "Some subject";
$body = ("Name: " . $name . "\nEmail Address: " . $email . "\nSome other text you may want in your subject etc");
$headers = 'From: mail@mail.com' . "\r\n" .
'Reply-To: mail@mail.com';
// CALL FUNCTION
sendMail($to, $subject, $body, $headers);
优良作法是使用函数来提升代码的可重用性。此邮件脚本现在不仅可用于此联系表单,还可以让您重新编写整个内容。
如果这不起作用(我已经测试了它并且它可以工作),它可能是您的服务器SendMail,要检查这是否已启用您可以创建一个PHPInfo并将其上传到您的FTP以检查sendmail是否已启用。
PHP信息:
<? phpinfo() ?>
我希望这有帮助, 丹