Skip to main content
Help Center
The GoDaddy Community will undergo maintenance starting on Tuesday, August 3rd at 3pm PST / 6pm EST. Learn more
  • GoDaddy Community
  • Building & Managing Client Sites
  • Building & Managing Client Sites

    cancel
    Showing results for 
    Show  only  | Search instead for 
    Did you mean: 
    Go to solution
    Dylancougar
    Getting Started

    Can send email using PHP contact form but recipients can't receive it when using yahoo email

    I'm trying to test out a simple email form on my website to see if I can get it to work. The email sends out just fine, but when I use my yahoo email address as the recipient for incoming emails to test it, no email ever arrives. I'm hard pressed to figure out why

     

    This is the PHP code I'm using.

     

     

    <?php
    
      // Message Vars
    	$msg = '';
    	$msgClass = '';
    
    	// Check For Submit
    	if(filter_has_var(INPUT_POST, 'submit')){
        // Get Form Data
    		$name = htmlspecialchars($_POST['name']);
    		$email = htmlspecialchars($_POST['email']);
        $message = htmlspecialchars($_POST['message']);
        
    		// Check Required Fields
    		if(!empty($email) && !empty($name) && !empty($message)){
    
          // Passed
    
          // Check Email
    			if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
            // Failed
    				$msg = 'Please use a valid email';
    				$msgClass = 'alert-danger';
          } else{
            // Passed
            // Recipient Email
            $toEmail = 'dylancougar@yahoo.com';
    				$subject = 'Contact Request From '.$name;
            $body = '<h2>Contact Request</h2>
    					<h4>Name</h4><p>'.$name.'</p>
    					<h4>Email</h4><p>'.$email.'</p>
    					<h4>Message</h4><p>'.$message.'</p>
            ';
            
            // Email Headers
    				$headers = "MIME-Version: 1.0" ."\r\n";
            $headers .="Content-Type:text/html;charset=UTF-8" . "\r\n";
            
            // Additional Headers
            $headers .= "From: " .$name. "<".$email.">". "\r\n";
            
    				if(mail($toEmail, $subject, $body, $headers)){
              // Email Sent
    					$msg = 'Your email has been sent';
    					$msgClass = 'alert-success';
            } else {
              // Failed
    					$msg = 'Your email was not sent';
    					$msgClass = 'alert-danger';
            }
    
          }
    
        } else {
          // Failed
          $msg = 'Please fill in all fields';
          $msgClass = 'alert-danger';
        }
      }
    
    ?>

     

     

     

    1 ACCEPTED SOLUTION
    Andy
    Community Manager

    Could be a few things. I did a quick search to see what others have done for troubleshooting PHP mail. This useful list came up in a Stack Overflow thread:

     

    • Does the sender address ("From") belong to a domain on your server? If not, make it so.
    • Is your server on a blacklist (e.g. check IP on spamhaus.org)? This is a remote possibility with shared hosting.
    • Are mails filtered by a spam filter? Also, try sending mail to an address without a spam filter.
    • Do you possibly need the fifth parameter "-f" of mail() to add a sender address? (See mail() command in the PHP manual)
    • If you have access to log files, check those, of course, as suggested above.
    • Do you check the "from:" address for possible bounce mails ("Returned to sender")? You can also set up a separate "errors-to" address.

     

    Let us know how you make out. 🙂

    Senior Community Manager, GoDaddy
    Need help with your GoDaddy.com account? Get 24/7 support at x.co/247support
    Find inspiration on the GoDaddy Blog
    Smash that Like button on GoDaddy's YouTube channel
    Follow @GoDaddy on Twitter, Instagram and LinkedIn

    View solution in original post

    2 REPLIES 2
    Andy
    Community Manager

    Could be a few things. I did a quick search to see what others have done for troubleshooting PHP mail. This useful list came up in a Stack Overflow thread:

     

    • Does the sender address ("From") belong to a domain on your server? If not, make it so.
    • Is your server on a blacklist (e.g. check IP on spamhaus.org)? This is a remote possibility with shared hosting.
    • Are mails filtered by a spam filter? Also, try sending mail to an address without a spam filter.
    • Do you possibly need the fifth parameter "-f" of mail() to add a sender address? (See mail() command in the PHP manual)
    • If you have access to log files, check those, of course, as suggested above.
    • Do you check the "from:" address for possible bounce mails ("Returned to sender")? You can also set up a separate "errors-to" address.

     

    Let us know how you make out. 🙂

    Senior Community Manager, GoDaddy
    Need help with your GoDaddy.com account? Get 24/7 support at x.co/247support
    Find inspiration on the GoDaddy Blog
    Smash that Like button on GoDaddy's YouTube channel
    Follow @GoDaddy on Twitter, Instagram and LinkedIn

    View solution in original post

    Dylancougar
    Getting Started

    So I'm guessing that the recipient for incoming emails has to be on a Go daddy server. I used my Godaddy email address and this time it actually worked.