php send mail form not working with emails on same domain [closed]

你。 提交于 2019-12-06 16:18:06

问题


I am trying to add a contact form to a website which posts the form data to an email address. It works fine with any other email registrants like Gmail and Yahoo. but it doesn't work with emails with same domain name (e.g.: info@domain.com or support@domain.com).

The same form was working fine with godaddy deluxe hosting but now that I have shifted to Godaddy CPanel linux hosting deluxe plan, it doesn't work.

Please go through the following code I am using and let me know what has to be changed. Your suggestions are greatly appreciated. Thanks in advance.

Code:

    <?php
if(isset($_POST['email'])) {


    $email_to = "info@domain.com";
    $email_subject = "Enquiry website";


    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please go back and fix these errors.<br /><br />";
        die();
    }

    // validation expected data exists
    if(!isset($_POST['author']) ||
        !isset($_POST['email']) ||
        !isset($_POST['subject']) ||    
        !isset($_POST['text'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

    $author = $_POST['author']; // required

    $email_from = $_POST['email']; // required
    $subject = $_POST['subject']; // required
    $text = $_POST['text']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z .'-]+$/";
  if(!preg_match($string_exp,$author)) {
    $error_message .= 'The Name you entered does not appear to be valid.<br />';

  }
  if(strlen($text) < 2) {
    $error_message .= 'The text you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
    died($error_message);
  }
    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name:".clean_string($author)."\n";

    $email_message .= "Email:".clean_string($email_from)."\n";
   $email_message .= "Subject:".clean_string($subject)."\n";
    $email_message .= "Message:".clean_string($text)."\n";


// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>

<!-- include your own success html here -->



<?php
  echo "<script type='text/javascript'>alert('$us Thank you for contacting us. We will get back to you very soon.')</script>";
echo "<script type='text/javascript'>window.location='index.html'</script>";
}
?>

回答1:


Not sure if this was added since this post, but you can actually set this yourself in cPanel.

  1. Click on MX Entry Icon under email.
  2. Select the domain from the dropdown that has your form.
  3. Select Remote email exchanger
  4. Hit change.



回答2:


Should you (or anybody) encounter this error in the future a simple phone call to Go Daddy will solve this issue. By default, Go Daddy's shared cPanel hosting is set to deliver local, not remote. If you have your email set anywhere besides cPanel's internal email accounts, the following test inside of your control panel will identify if you need to request remote email delivery:

In the email section of the cPanel main page select the option 'Email Trace' Type your domain email in the 'Recipient Email...' box and select 'Run Report'

If the output reads 'Blackhole' on the second line then you're configured for local delivery, contact their hosting support department and request the change to remote delivery. You'll be up and running within a few minutes if you mention having performed this test prior to calling.




回答3:


Do you have you email configured on this domain. i.e. are you MX servers set locally or to another provider?

php mailer / cPanel will not check external DNS for it's own domain (unless you tell it to) when sending mail, it will simply send the mail to itself... If you are not configured locally on your server to receive mail, then you will not get the email.



来源:https://stackoverflow.com/questions/20972812/php-send-mail-form-not-working-with-emails-on-same-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!