PHP邮件处理程序不发送

时间:2015-05-12 17:51:45

标签: php html forms email

我在使用php电子邮件处理程序时遇到了一些问题。我之前使用过相同的脚本,但出于某种原因,它不会发送电子邮件。任何帮助是极大的赞赏。 这是带有我需要的字段和标签的html表单。 HTML:

<form class="flat white vertical corporate-lead-form" method="POST" form action="php/mail-handler.php">
            <label for="name">Nombre Completo</label>
            <input id="name" type="text" name="name" maxlength="30" autocomplete="off" required />
            <label for="phone">Tel&#233;fono</label>
            <input id="phone" type="text" name="phone" maxlength="30" autocomplete="off" required />
            <label for="email-adress">Email</label>
            <input id="email-adress" type="text" name="email-adress" maxlength="30" autocomplete="off" required />
            <label for="location">Ciudad</label>
            <input id="location" type="text" name="location" maxlength="30" autocomplete="off" required />
            <label for="comments">Comentarios</label>
            <textarea name="comments" id="comments" rows="2" cols="20" required="required"></textarea>
            <input type="submit" name="submit" id="submit" value="Enviar" />
        </form>

这是我使用的表单处理程序文件   PHP:

    <?php 
    $errors = '';
    $myemail = 'eduardo@portafoliobranding.com';//<-----Put Your email address here.
    if(empty($_POST['name'])  || 
     empty($_POST['email']))
    {
    $errors .= "\n Error: all fields are required";
    }

    $name = $_POST['name']; 
    $email_address = $_POST['email'];
    $phone = $_POST['phone'];
    $location = $_POST['location'];
    $comments = $_POST['comments'];

    if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address))
    {
    $errors .= "\n Error: Invalid email address";
    }

    if( empty($errors))
    {
     $to = $myemail; 
     $email_subject = "Contact form submission: $name";
     $email_body = "You have received a new message. ".
     " Here are the details:\n Name: $name \n Email: $email_address \n Tel: \n $phone \n Ubicación: \n $location \n Comentarios: \n $comments";
    }
$headers = "From: $myemail\n"; 
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header("Location: /index.html");
exit();
?>

0 个答案:

没有答案