简体   繁体   English

PHP邮件表单问题

[英]PHP mail form problems

I'm creating a simple mail form with checkboxes, a couple of input tabs, and a text input section. 我正在创建一个带有复选框,几个输入选项卡和一个文本输入部分的简单邮件表单。 It uses PHP to retrieve the information then email it to a specific email. 它使用PHP检索信息,然后通过电子邮件将其发送到特定的电子邮件。 Right now I have it emailing to my own yahoo email just for testing. 现在,我已经将其通过电子邮件发送到我自己的yahoo电子邮件以进行测试。 When I test the site on my hosting account jacobbuller.com/testsites/peacock/contact.php the form works perfectly and forwards the email from my generic "theski" server email. 当我在托管帐户jacobbuller.com/testsites/peacock/contact.php上测试站点时,该表单可以正常运行并转发来自我的通用“ theski”服务器电子邮件的电子邮件。 But when I upload the site to the actually live hosting account for peacockautoservice.com the contact form works - it executes and sends a ?msg=1 variable in the url - but I never receive the email in my Yahoo account... 但是,当我将网站上传到peacockautoservice.com的实际实时托管帐户时,联系表单有效-它执行并在URL中发送?msg = 1变量-但我从未在Yahoo帐户中收到电子邮件...

Here's the PHP I am using to send the email. 这是我用来发送电子邮件的PHP。

<?php ob_start();
<?php 
$required_field = array('name', 'email', 'message');
foreach($required_field as $fieldname) {
if (!isset($_POST[$fieldname])) {
  $errors[] = $fieldname;
}}
if (empty($errors)) {
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$contact = $_POST['contact'];
$phone = $_POST['phone'];
$services = IsChecked('checkboxes', 'factory');
$services .= IsChecked('checkboxes', 'timing belt');
$services .= IsChecked('checkboxes', 'brakes');
$services .= IsChecked('checkboxes', 'computerized');
$services .= IsChecked('checkboxes', 'steering and suspension');
$services .= IsChecked('checkboxes', 'heating and air');
$services .= IsChecked('checkboxes', 'electrical');
$services .= IsChecked('checkboxes', 'other');
$body = "Customer:" . $name;
$body.= "Phone Number:" . $phone;
$body.= "Contact:" . $contact;
$body.= "Services:" . $services;
$body.= "Message:" . $message;
$to = "jcbbuller@yahoo.com";
$subject = "Peacock Auto Services Inquirey";
$from = $email;
$mailed = mail($to, $subject, $body, $from) or die("Error!");
 }
if($mailed) {
    redirect_to("../contact.php?msg=1");
}

 ?>
 <?php
 // IsChecked FUNCTION - Detemines what checkbox are/aren't checked on form.
 function IsChecked($postname, $value){ 
    if(!empty($_POST[$postname])) {
        foreach($_POST[$postname] as $job) {
        if ($job == $value) {
            $project = "  ". $value . "  ";
            return $project;

            }
        }
    }
  } //END IsChecked FUNCTION

 function redirect_to( $location = NULL ) {
    if ($location != NULL) {
        header("Location: {$location}");
        exit;
        }
     }   
 ?>
 <?php ob_end_flush(); ?>

Please let me know if you see something wrong with the PHP above or if you know why their GoDaddy hosting account is not executing the email. 如果您发现上述PHP出了点问题,或者知道为什么他们的GoDaddy托管帐户未执行电子邮件,请告诉我。 I tried using their customer service network but they said that they can't help me with my code... 我尝试使用他们的客户服务网络,但是他们说他们不能帮我编写我的代码...

Your issue is mainly at server end. 您的问题主要在服务器端。 Mail function is working because of your check on it, if it had failed, it would have given you notification. 邮件功能正在运行,因为您对其进行了检查,如果失败了,它将通知您。 So, mails are going definitely. 因此,邮件肯定会发送。 If mail server is working properly at your production server, then check for SPAM folder at yahoo mail server. 如果邮件服务器在您的生产服务器上正常工作,请在yahoo邮件服务器上检查SPAM文件夹。 I would suggest you to ask your hosting provider to enable SPF and DKIM records because most of email providers requires sender authentication (if it is not a spam) and these records are helpful in it. 我建议您要求托管服务提供商启用SPF和DKIM记录,因为大多数电子邮件提供商都需要发件人身份验证(如果它不是垃圾邮件),而这些记录将对您有所帮助。

I can also see that your not using any headers, so I would suggest you to use extended headers to avoid providers identifying you as a spammer. 我还可以看到您没有使用任何标头,因此建议您使用扩展标头,以避免提供程序将您标识为垃圾邮件发送者。 I use below mentioned headers and my emails never go in spam on anyprovider, but again it depends on IP reputation of the server as well. 我使用下面提到的标头,并且我的电子邮件从未在anyprovider上发送垃圾邮件,但这同样取决于服务器的IP信誉。

    $headers .= "Reply-To: Awaraleo <email@domain.org>\r\n";
    $headers .= "Return-Path: Awaraleo <email@domain.org>\r\n";
    $headers .= "From: Awaraleo <email@domain.org>\r\n"; 
    $headers .= "Organization: Awaraleo\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "X-Priority: 3\r\n";
    $headers .= "X-Mailer: PHP". phpversion() ."\r\n";

and then use it like 然后像

mail($to,$subject,$message,$headers);

Here email@domain.org should be a valid email address created on the domain where this form is implemented. 这里的email@domain.org应该是在实施此表单的域上创建的有效电子邮件地址。

Another authentic way is to use SMTP Authentication in coding. 另一种可靠的方法是在编码中使用SMTP身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM