doucan8276 2015-02-05 04:49
浏览 13
已采纳

PHP POST方法,不发送电子邮件

I need some help. I have a contact formulary for a website, but it isnt sending the email, however the message I programmed to tell its working, popa up right.

Heres the HTML

<!doctype html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, maximum-scale=1.0, minimum-scale=1.0">
<title>Untitled Document</title>
<link href="CSS/Principal.css" rel="stylesheet" type="text/css">
<link href="fonts.css" rel="stylesheet" type="text/css">
</head>

<body>
<header>
</header>
<section class="formulario">
    <form action="contacto.php" method="post">
      <p>
        <label for="nombre">Nombre:</label>
        <input id="nombre" type="text" name="nombre" placeholder="Nombre, Apellido y/o escuela" required="" />
        <label for="email">Email:<br>
        </label>
        <input id="email" type="email" name="email" placeholder="ejemplo@nightjunkies" required="" />
        <label for="mensaje">Mensaje:</label>
        <textarea id="mensaje" name="mensaje" placeholder="Mensaje" required>    </textarea>
        <input id="submit" type="submit" name="submit" value="Enviar" />
      </p>
    </form>

  </section>

</body>
<footer>
<p class="footer">Powered By Xanmaya&copy;
</footer>
</html>

And here`s the PHP used

<?php
$nombre = $_POST['nombre'];
$email = $_POST['email'];
$mensaje = $_POST['mensaje'];
$para = 'villasantdesign@gmail.com';
$titulo = 'ASUNTO DEL MENSAJE';
$header = 'From: ' . $email;
$msjCorreo = "Nombre: $nombre
 E-Mail: $email
 Mensaje:
 $mensaje";

if ($_POST['submit']) {
if (mail($para, $titulo, $msjCorreo, $header)) {
echo "<script language='javascript'>
alert('Mensaje enviado, muchas gracias.');
window.location.href = 'http://nightjunkies.com.mx';
</script>";
} else {
echo 'Falló el envio';
}
}
?>

Ill appreciate some help

Finally I fixed it using PHPMailer instead

<?php
require 'phpmailer/PHPMailerAutoload.php';
if(isset($_POST["submit"] ))
{
    $nombrede = "Administrador";
    $de = 'example@domain.com';
    $nombre = $_POST["nombre"];
    $email = $_POST["email"];
    $mensaje = $_POST["mensaje"];

    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->Host = 'smtp1.example.net';
    $mail->SMTPAuth = true;
    $mail->Username = 'example@mydomain.com';
    $mail->Password = 'password';
    $mail->Port = 80;

    $mail->From = $email;
    $mail->FromName = $nombre;
    $mail->addAddress($de, $nombrede);

    $mail->Subject = "Contacto Night Junkies";
    $mail->Body = $mensaje;

    if($mail->Send())
    {
        echo "<script language='javascript'>
alert('Mensaje enviado, muchas gracias.');
window.location.href = 'http://nightjunkies.com.mx';
</script>";
    } else {
        echo 'Hubo un problema';
        echo 'Mailer Error: ' . $mail->ErrorInfo;


}
}
?>
  • 写回答

3条回答 默认 最新

  • doudinghan8319 2015-02-05 05:08
    关注

    There are a lot of reasons this might not work. How is PHP configured to handle mail()? Does that work from the server? You're also likely raising SPAM flags or simply being blocked. A better way to send reliable email is to setup an SMTP account and send the mail from that authenticated account. PHPMailer may help speed things up for you.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀