Highlighted

PHP, Yahoo Error

Explorer ,
Mar 09, 2018

Copy link to clipboard

Copied

I am building a website that has a comment section for clients to type in their name, their email address, and any comments they may have for the business. This email form is sent to a php page that I have created. During my test run, the content was sent succesful to a gmail account; however, the content will not send to a yahoo email address (the business owner has a yahoo email address).

I was wondering as to why this content will send successfully to a gmail account, and not a yahoo account. The code is as follows:

<?php

$errors = '';

$myemail = 'jondoe@yahoo.com';//<-----Put Your email address here.

if(empty($_POST['customerName'])  ||

   empty($_POST['emailAddress']) ||

   empty($_POST['emailComment']))

{

    $errors .= "\n Error: all fields are required";

}

$name = $_POST['customerName'];

$email_address = $_POST['emailAddress'];

$message = $_POST['emailComment'];

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";

}

//above is making sure the content is valid

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 Message \n $message";

  $headers = "From: $myemail\n";

  $headers .= "Reply-To: $email_address";

  mail($to,$email_subject,$email_body,$headers);

  //redirect to the 'thank you' page

  header('Location: contact-form-thank-you.html');

}

?>

<!DOCTYPE HTML>

<html>

<head>

  <title>Contact form handler</title>

</head>

<body>

<!-- This page is displayed only if there is some error -->

<?php

echo nl2br($errors);

?>

</body>

</html>

Adobe Community Professional
Correct answer by Nancy OShea | Adobe Community Professional

webmaster@yourdomain.com is a legitimate email on the server.  It's going to send the form data to you.   Change it to whatever email account is already set-up for the server.   If unsure what to use, contact the web hosting provider.  

Views

3.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

PHP, Yahoo Error

Explorer ,
Mar 09, 2018

Copy link to clipboard

Copied

I am building a website that has a comment section for clients to type in their name, their email address, and any comments they may have for the business. This email form is sent to a php page that I have created. During my test run, the content was sent succesful to a gmail account; however, the content will not send to a yahoo email address (the business owner has a yahoo email address).

I was wondering as to why this content will send successfully to a gmail account, and not a yahoo account. The code is as follows:

<?php

$errors = '';

$myemail = 'jondoe@yahoo.com';//<-----Put Your email address here.

if(empty($_POST['customerName'])  ||

   empty($_POST['emailAddress']) ||

   empty($_POST['emailComment']))

{

    $errors .= "\n Error: all fields are required";

}

$name = $_POST['customerName'];

$email_address = $_POST['emailAddress'];

$message = $_POST['emailComment'];

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";

}

//above is making sure the content is valid

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 Message \n $message";

  $headers = "From: $myemail\n";

  $headers .= "Reply-To: $email_address";

  mail($to,$email_subject,$email_body,$headers);

  //redirect to the 'thank you' page

  header('Location: contact-form-thank-you.html');

}

?>

<!DOCTYPE HTML>

<html>

<head>

  <title>Contact form handler</title>

</head>

<body>

<!-- This page is displayed only if there is some error -->

<?php

echo nl2br($errors);

?>

</body>

</html>

Adobe Community Professional
Correct answer by Nancy OShea | Adobe Community Professional

webmaster@yourdomain.com is a legitimate email on the server.  It's going to send the form data to you.   Change it to whatever email account is already set-up for the server.   If unsure what to use, contact the web hosting provider.  

Views

3.6K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 09, 2018 0
Adobe Community Professional ,
Mar 09, 2018

Copy link to clipboard

Copied

Did you make sure it didn't end up in a spam folder at yahoo?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 09, 2018 1
Explorer ,
Mar 10, 2018

Copy link to clipboard

Copied

I did, I checked each folder over and over again. When I sent it to a gmail account it took about 5 minutes to receive.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 10, 2018 0
LEGEND ,
Mar 11, 2018

Copy link to clipboard

Copied

I detect two potential problems with your script:

  • Email headers should be separated by a carriage return and newline character. You're using only a newline character. The first line of your $headers should end with "\r\n" rather than "\n".
  • The From header should indicate where the email is being sent from. You're using the same address as the one the email is being sent to. Change the From header to a genuine email address that exists on the domain that the form is hosted on.

Many mail servers reject email that comes from an unrecognized source. Using the same address as the destination is almost certainly being treated as spam.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 1
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

David,

Your right about your first point, however I'm not understanding your second point. $myemail is the genuine email that is being used to receive any messages from potential clients. $email_address is the customers email address.

These two are different. Not sure what you mean by I am using the same address as the one the email is being sent to.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Adobe Community Professional ,
Mar 11, 2018

Copy link to clipboard

Copied

Create a legitimate email address on your server -- webmaster@your_domain.com.  Use that as the sending email.

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

But my client is wanting he's personal email account to be the sending email. In previous tests I used my personal gmail account that emails sent successfully; however when I use his email address (a yahoo account) the email's send unsuccessfully.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Adobe Community Professional ,
Mar 11, 2018

Copy link to clipboard

Copied

You don't understand.  I'm talking about the sending email on the server, not the address to which you receive mail.  2 different things.

Nancy

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

Your right, I'm not understanding. Thats why I am posting this on here, could you help me to understand? You have my code at the top, could you "dumb it down" for me?

Thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Adobe Community Professional ,
Mar 11, 2018

Copy link to clipboard

Copied

I have a 3-part tutorial on this below.

Alt-Web Design & Publishing: Responsive Contact Form with Bootstrap and PHP (Part 1)

Copy & paste the following code into a new, blank PHP document.  File > SaveAs contact.php. 

<?php

// NOTE: this page must be saved as a .php file.

// And your server must support PHP 5.3+ and php Mail().

// Define variables and set to empty values

$result = $name = $email = $phone = $message = $human = "";

$errName = $errEmail = $errPhone = $errMessage = $errHuman = "";

    if (isset($_POST["submit"])) {

        $name = $_POST['name'];

        $email = $_POST['email'];

        $phone = $_POST['phone'];

        $message = $_POST['message'];

        $human = intval($_POST['human']);

    //valid address on your web server

        $from = 'webmaster@yourdomain.com';

   //your email address where you wish to recieve mail

        $to = 'name@email.com';

        $subject = 'MESSAGE FROM YOUR WEB SITE';

        $headers = "From:$from\r\nReply-to:$email";

        $body = "From: $name\n E-Mail: $email\n Phone: $phone\n Message: $message";

// Check if name is entered

if (empty($_POST["name"])) {

$errName = "Please enter your name.";

} else {

    $name = test_input($_POST["name"]);

}

// Check if email is entered

if (empty($_POST["email"])) {

$errEmail = "Please enter your email address.";

} else {

    $email = test_input($_POST["email"]);

    // check if e-mail address is valid format

    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {

      $errEmail = "Invalid email format.";

    }

}

// Check if phone is entered

if (empty($_POST["phone"])) {

$phone = "";

} else {

    $phone = test_input($_POST["phone"]);

}

//Check if message is entered

if (empty($_POST["message"])) {

$errMessage = "Please enter your message.";

} else {

    $message = test_input($_POST["message"]);

}

//Check if simple anti-bot test is entered

if (empty($_POST["human"])) {

$errHuman = "Please enter the sum.";

} else {

     if ($human !== 12) {

     $errHuman = 'Wrong answer. Please try again.';

        }

}

// If there are no errors, send the email & output results to the form

if (!$errName && !$errEmail && !$errPhone &&  !$errMessage && !$errHuman) {

    if (mail ($to, $subject, $body, $from)) {

        $result='<div class="alert alert-success"><h2><span class="glyphicon glyphicon-ok"></span> Message sent!</h2><h3>Thank you for contacting us. Someone will be in touch with you soon.</h3></div>';

    } else {

        $result='<div class="alert alert-danger"><h2><span class="glyphicon glyphicon-warning-sign"></span> Sorry there was a form processing error.</h2> <h3>Please try again later.</h3></div>';

       }

    }

}

    //sanitize data inputs   

    function test_input($data) {

   $data = trim($data);

   $data = stripslashes($data);

   $data = htmlspecialchars($data);

    $data = (filter_var($data, FILTER_SANITIZE_STRING));

   return $data;

}

//end form processing script

?>

<!doctype html>

<html lang="en">

<head>

<meta charset="utf-8">

<title>Contact Form </title>

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta http-equiv="X-UA-Compatible" content="IE=edge">

<!-- Latest compiled and minified Bootstrap CSS-->

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<style>

.required {color:red; font-weight:bold}

.center-block {float:none}

.human {margin: 0 0 0 12px}

</style>

</head>

<body>

<div class="container">

<div class="row">

<div class="col-lg-8 col-lg-offset-2">

<h5>NOTE: This script is not connected to an actual email address yet. Change it to yours on Line 16 of the PHP code. </h5>

<div class="col-md-8 center-block">

<h3>Responsive Contact Form</h3>

<p class="required small">* = Required fields</p>

<!--begin HTML Form-->

<form id="myContact" class="form-horizontal" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

<!--when submit button is clicked, show results here-->

<div class="form-group">

<div class="col-sm-10 col-sm-offset-2">

<?php echo $result;?>

</div>

</div>

<div class="form-group">

<label for="name" class="col-sm-3 control-label"><span class="required">*</span> Name:</label>

<div class="col-sm-9">

<input type="text" class="form-control" id="name" name="name" placeholder="First & Last" value="<?php echo $name; ?>">

<span class="required small"><?php echo $errName; ?></span>

</div>

</div>

<div class="form-group">

<label for="email" class="col-sm-3 control-label"><span class="required">*</span> Email: </label>

<div class="col-sm-9">

<input type="email" class="form-control" id="email" name="email" placeholder="you@domain.com" value="<?php echo $email; ?>">

<span class="required small"><?php echo $errEmail;?></span>

</div>

</div>

<div class="form-group">

<label for="phone" class="col-sm-3 control-label">Phone: </label>

<div class="col-sm-9">

<input type="tel" class="form-control" id="phone" name="phone" placeholder="(123) 456-7890" value="<?php echo $phone; ?>">

<span class="required small"><?php echo $errPhone;?></span>

</div>

</div>

<div class="form-group">

<label for="message" class="col-sm-3 control-label"><span class="required">*</span> Message:</label>

<div class="col-sm-9">

<textarea class="form-control" rows="4" name="message" id="message" placeholder="Tell us your story"><?php echo $message;?></textarea>

<span class="required small"><?php echo $errMessage;?></span>

</div>

</div>

<div class="form-group">

<label for="human" class="col-sm-3 control-label"><span class="required">*</span> Human Test:</label>

<div class="col-sm-4">

<h3 class="human">6 + 6 = ?</h3>

<input type="text" class="form-control" id="human" name="human" placeholder="Your Answer" value="<?php echo $human; ?>">

<span class="required small"><?php echo $errHuman;?></span>

</div>

</div>

<div class="form-group">

<div class="col-sm-offset-3 col-sm-6 col-sm-offset-3">

<button type="submit" id="submit" name="submit" class="btn-lg btn-primary btn-block">SUBMIT</button>

</div>

</div>

<!--end Form--></form>

<!--end col block--></div>

<!--end col--></div>

<!--end row--></div>

<!--end container--></div>

<!--jQuery 3.2 minified-->

<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<!--Bootstrap 3.7 minified-->

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

</body>

</html>

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 2
LEGEND ,
Mar 11, 2018

Copy link to clipboard

Copied

ikevin12  wrote

I'm not understanding your second point. $myemail is the genuine email that is being used to receive any messages from potential clients. $email_address is the customers email address.

These two are different. Not sure what you mean by I am using the same address as the one the email is being sent to.

Yes, both email addresses are different, but you're using $myemail both as the value of $to (the destination of the email), and as the value of the From header.

$headers = "From: $myemail\n";

$headers .= "Reply-To: $email_address";

The From header MUST be an email address on the web server that's hosting the form. It describes where the email is coming from. The fact that your client wants it to look as though it's coming from himself makes no difference. He's not sending it. The form is.

Most mail servers will reject emails that come from a different source than the value in the From header. OK, it worked with your Gmail experiment. The reason it's not working with the Yahoo address is that the mail server is rejecting mail coming from a source that claims to be one thing, but is in fact something else.

Let's say the form is on example.com, your headers should look like this:

$headers = "From: webmaster@example.com\r\n";

$headers .= "Reply-to: $email_address";

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 1
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

David,

I think I might of created a mess out of my html, and php code. I understand what you are talking about regarding I'm using both email addresses as the value of $to and as the From header. I am doing this as a "call" method you could say?

My html form code is as follow:

<form class="commentSection" method="post" name="contactform" action="contact-form-handler.php">

  <p id="userName">Name:</p>

  <p id="customerEmail">Email:</p>

  <p id="customerComment">Comment:</p>

  <input class="customerName" name="customerName" type="text">

  <input class="emailAddress" name="emailAddress" type="text">

  <textarea class="emailComment" name="emailComment" rows="8" cols="50"></textarea>

  <input class="button" type="submit" value="Send" height="47px">

</form>

The input class "emailAddress" has its own css, and I gave it the name of "emailAddress". In the php code I am calling the input of the user by the name of "emailAddress".

I guess I did this to "call" whatever the user inputs in the text box. This is why I have

$headers = "From: $myemail\n";

$headers .= "Reply-To: $email_address";

Now I am lost, maybe I did the whole thing wrong?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

Let me explain EXACTLY what the client is wanting, and EXACTLY what I did to get to this point.

My client wanted a website with a contact form at the bottom of the site giving the user an option to send the business owner their name, email address, and any comment they may have concerning his business.

I used html to build a simple website for the owner, I then googled PHP code's that will take anything the user inputs and in return send it to the business owners email address (I have zero experience in php, so I used google).

I used the code provided from google (it was a trial and error type deal) until I finally tested the right code that returned the test run to my personal email address (gmail). I thought I finished the site due to the success of the php code sending my personal message to my gmail account, so I switched my gmail account in the php code to the business owner's personal email address (a yahoo account). None of the emails was getting sent to him like it did with me. Now I am here.. Lost..

Not too sure where to go from here, again I have no experience in php. I didn't understand why it worked with my gmail pose to his yahoo account.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Adobe Community Professional ,
Mar 11, 2018

Copy link to clipboard

Copied

I posted a working PHP contact form above.

Did you add the yahoo email address to line 16 of the code?  Then save & upload to server to test?

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

Nancy,

I have to have this website finished within the hour. I am currently reading your blog from the website you provided above to gain an understanding on what I should do.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

You provided html code, and when I copy and paste the code you provided it confused me.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Adobe Community Professional ,
Mar 11, 2018

Copy link to clipboard

Copied

I can't help you meet an impossible deadline.  Copy the code I provided into a new, BLANK document and save as contact.php .    On line 16 in code view, change the TO email address to your yahoo account. 

Upload to server to test.

Nancy

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Explorer ,
Mar 11, 2018

Copy link to clipboard

Copied

I appreciate the help you guys have gave me, Nancy the website you provided (I assume it is your website) is a great resource to me!

Im not understanding the email address has to be the web server thats hosting the form. Nancy, in the code you provided you use 'webmaster@yourdomain.com'. I don't understand this, should I switch that with something else? I apologize again, I am new. This is my first client, however I am excited to learn. Just trying to understand.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0
Adobe Community Professional ,
Mar 11, 2018

Copy link to clipboard

Copied

webmaster@yourdomain.com is a legitimate email on the server.  It's going to send the form data to you.   Change it to whatever email account is already set-up for the server.   If unsure what to use, contact the web hosting provider.  

Nancy O'Shea, ACP
Alt-Web Design & Publishing

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 11, 2018 0