根据从下拉列表中选择的选项发送电子邮件



我有这个表格,它工作正常,但在雅虎有时它会向垃圾邮件文件夹发送电子邮件。知道吗?谢谢。

这是 html:

<form name="frm" id="frm" method="POST" action="contact.php">
    <label>Name</label>
    <input type="text" name="name" id="name" class="validate[required,custom[alphaspace]] for_obj" />
    <label>Company Name</label>
    <input type="text" name="company" id="company" />
    <label>Email</label>
    <input type="text" name="email" id="email" class="validate[required,custom[email]] for_obj" />
    <label>Phone</label>
    <input type="text" name="phone" id="phone" />
    <label>Country Name</label>
    <input type="text" name="country" id="country" class="validate[required,custom[alphaspace]] for_obj" />
    <label>Interested</label>
    <select type="text" name="interested" id="interested" class="validate[required,custom[alphaspace]] for_obj">
      <option value="select">--Select--</option>
      <option value="Information">Information</option>
      <option value="Product">Product</option>
      <option value="Career">Career</option>
      <option value="Others">Others</option>
    </select>
    <label for="message">Message</label>
    <textarea name="message" id="message" class="validate[required] for_obj" rows="8" cols="10"></textarea>
    <input type="submit" value="Send" class="butt custom_font" />
    <input type="reset" value="reset" class="butt custom_font" />
</form>

这是PHP:

    <?php
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$country = $_POST['country'];
$interested = $_POST['interested'];
$message = $_POST['message'];
$formcontent="From: $name n Company Name: $company nPhone: $phone n Country Name: $country nInterested: $interested n Message: $message";
if ($interested == 'Information') { 
    $to = 'information@mysite.com';
}
else if ($interested == 'Product') { 
    $to = 'product@mysite.com'; 
}
else if ($interested == 'Career') { 
    $to = 'career@mysite.com'; 
}
else { //other options
    $to = 'others@mysite.com'; 
}
$subject = "Enquiry from Website";
$mailheader = "From: $email rn";
mail($to, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You! <br /> We will get in touch with you as soon as possible.";
?>
我认为你可以像我使用 PHPMailer 库

一样解决这个问题 也许雅虎正在将您的电子邮件发送到垃圾邮件文件夹,因为它们需要验证,而 PHPMailer 允许您使用您的表单进行 SMTP 设置,这是一个很好的库试试吧! 不错的编码。

相关内容

最新更新