My email form is working but will not send an email when the user uses a aol.com and yahoo.com email address. What do I need to change?
PHP file is hosted by godaddy.
I'm a designer, and PHP is not my forte, can you explain an answer with changes to my existing code (if the change is with the code at all.) This problem is very frustrating.
// Only process POST reqeusts.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
// http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Set the recipient email address.
// FIXME: Update this to your desired email address.
$recipient = "mysite#mysite.com";
// Set the email subject.
$subject = "New contact from $name";
// Build the email content.
$email_content = "Name: $name\n";
$email_content .= "Email: $email\n\n";
$email_content .= "Message:\n$message\n";
// Build the email headers.
$email_headers = "From: $name <$email>";
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers)) {
//Set a 200 (okay) response code.
// http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
// Set a 500 (internal server error) response code.
// http_response_code(500);
echo "Oops! Something went wrong and we couldn't send your message.";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
// http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
The only thing that I can think of is that goDaddy has blocked these domains for sending emails, since mail() uses the servers settings
I also don't see any error in your simple code. Some things to consider:
Your new lines in the body and header should use CRLF \r\n, rather simply \n
You may also use additional parameters and setting your email as 5th parameter with the -f command (trusted user for the sending program).
Example:
// Send the email.
if (mail($recipient, $subject, $email_content, $email_headers,"-f".$email)) {
Since you're a designer, i also suggest to use tools like PHPMailer, that eases the e-mailing process and fixes some stuff for you.
Well that's because you're not supposed to be sending mail on behalf of email addresses you don't control through mail servers that are not authorized to do so. This is a rule about email that most people seem to ignore, but both Yahoo and AOL have both recently changed their policies to block the exact thing you are trying to do.
http://blog.mailchimp.com/aol-changes-dmarc-policy/
I would expect that this will become a thing that more and more mail providers do as time goes on.
What you should be doing is using an email address that you own to send out the mail, either through that domains outbound server or one authorized by the domain, and not trying to spoof someone else's address. In addition to not appearing to be shady as all get-out, you'll be far less likely to run afoul of DMARC and SPF policies, spam filters, and angry email admins perusing StackOverflow.
I tore out my hair over this issue for weeks. Finally figured it out today. If your form has an email field and it's named "email", and the user types an #aol or #yahoo email address, Formmail will act like nothing's wrong, but the form will not be sent.
It's an easy fix. Just use something else (anything else but "email") for the email field name, like "FromEmail".. Easy peasy.
If the user types something like dingbat#aol.com or doofus#yahoo.com:
This won't work:
<input type="text" name="email" size="30" maxlength="100" />
but this will:
<input type="text" name="FromEmail" size="30" maxlength="100" />
Good luck!
Chaz
Related
I'm trying to have entered email address delivered to my inbox so that when user enters his email in form, I get an email notification about it.
This is the php:
<?php
if($_POST){
$email = $_POST['email'];
//send email
mail("email#email.com", "Newsletter Signup:" .$email);
}
?>
What am I doing wrong since it's not working atm ?
What is the problem with this question
The reason why your mails won't be delivered can be really anything. Check the environments of your mailserver and your webserver.
Check your Email Account for spam filters
Maybe your internet provider is blocking the email because of unverified sender address
Firewalls problems
etc...
How to solve the problem
Since the mail() function implementation in php is returning a boolean, you can use this return value to detect an error:
<?php [...]
$email = $_POST['email'];
$success = mail("email#email.com", "Newsletter Signup:", $email);
if (!$success) {
$error = error_get_last();
var_export($error);
}
[...] ?>
Maybe this will help you to locate the problem.
Below is the Webform PHP code I used for e-mail function. After I click the SUBMIT button in the form, I am successfully getting redirected to the thankyou.html page but I don't get any e-mail to my e-mail account. Kind help is deeply appreciated.
PHP Code:
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
mail('myemail#email.com', 'Subject Line', $emailbody);
header('location: thankyou.html');
} else {
header('location: index.html');
}
?>
You may be missing the "From" field in the $additional_headers argument. Try
$headers = 'From: myemail#email.com';
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
It might be a problem with your host.
I think due to the email spams that #email.com got from your host it may be now in the blacklist.
This means you have to contact your host about this problem and tell them to talk with #email.com to remove your host from the blacklist.
I had this problem a while ago on 000webhost.com and they told me i can't send emails to an yahoo.com account because yahoo.com added the 000webhost.com on the blacklist because users spammed the Yahoo servers.
It's likely that your server, or one along the route, is refusing to deliver the mail because it has no From: address. You can add one using the headers parameter for mail():
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
// Add extra headers here
$headers = "From:address#examle.com"
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
header('location: index.html');
} else {
header('location: about-us.html');
}
You should check any user-suplied input to ensure it doesn't try to subvert your mail function by adding headers of its own. Check for text like To:, Cc: or Bcc:.
Most ISPs will refuse to deliver email unless it comes from a domain registered with them. Sometimes the from address must exist on the server generating the mail.
Note that there are other reasons why mail might not be delivered: bad addressing and spam filters to name but two.
I found the answer. I just changed $emailbody into $message and it is working fine now. I am not sure that using $emailbody instead of $message was the issue but it is working fine now.
Thank you all.
First check your hosting server is that providing mail functionality for this you just write
echo phpinfo();
you need to check the mail function enable or not
http://www.bridgetjoy.com/Web/requestInfo.html
I am having trouble getting the above form to process...here is my php processing code, I am getting it to redirect to my success page but it is not showing up in my inbox. Any help would be appreciated. Thanks!
<?php
if(isset($_POST['submit'])) {
$to = "bridgetjoymedia#gmail.com" ; //put your email address on which you want to receive the information
$subject = "Information Request"; //set the subject of email.
$headers = "From: $email";
$message = "<table><tr><td>Title :</td><td>".$_POST['title']."</td></tr>
<tr><td>First Name :</td><td>".$_POST['firstName']."</td></tr>
<tr><td>Last Name :</td><td>".$_POST['lastName']."</td></tr>
<tr><td>Degree :</td><td>".$_POST['degree']."</td></tr>
<tr><td>Address :</td><td>".$_POST['address1']."</td></tr>
<tr><td> </td><td>".$_POST['address2']."</td></tr>
<tr><td> </td><td>".$_POST['address3']."</td></tr>
<tr><td>City :</td><td>".$_POST['city']."</td></tr>
<tr><td>State :</td><td>".$_POST['state']."</td></tr>
<tr><td>ZipCode :</td><td>".$_POST['zipCode']."</td></tr>
<tr><td>Country :</td><td>".$_POST['country']."</td></tr>
<tr><td>E-mail Address :</td><td>".$_POST['email']."</td></tr>
<tr><td> Secondary E-mail Address :</td><td>".$_POST['email2']."</td></tr>
<tr><td>Primary Phone :</td><td>".$_POST['phone1']."</td></tr>
<tr><td>Primary Phone Location :</td><td>".$_POST['phone1_location']."</td></tr>
<tr><td>Secondary Phone :</td><td>".$_POST['phone2']."</td></tr>
<tr><td>Secondary Phone Location :</td><td>".$_POST['phone2_location']."</td></tr>
<tr><td>Fax :</td><td>".$_POST['phone3']."</td></tr>
<tr><td>Reason for Request :</td><td>".$_POST['relation']."</td></tr>
<tr><td>Reason for Request :</td><td>".$_POST['relation_specify']."</td>
<tr><td>Reason for Request :</td><td>".$_POST['physician_specialty']."</td>
<tr><td>Reason for Request :</td><td>".$_POST['surgeon_specialty']."</td>
<tr><td>Reason for Request :</td><td>".$_POST['prof_specify']."</td></tr>
<tr><td>Reason for Request :</td><td>".$_POST['other_specify']."</td></tr>
<tr><td>Diagnosis :</td><td>".$_POST['diagnosis']."</td></tr>
<tr><td>Insurance :</td><td>".$_POST['insurance']."</td></tr>
<tr><td>How did you hear of Avery Biomedical :</td><td>".$_POST['source']."</td></tr>
<tr><td>Comments :</td><td>".$_POST['comments']."</td></tr>
</table>" ;
$send_contact = mail($to,$subject, $headers,$message);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
header("Location: success.html");
exit();}
else {
header("Location: failure.html");
exit();}
}
?>
Emails sent by mail() function is blocked due is used by scammers try to use sendmail from PEAR or a smtp class
phpmailer https://code.google.com/a/apache-extras.org/p/phpmailer/
PEAR sendmail https://pear.php.net/manual/en/package.mail.mail.send.php
Look at PHP: mail() vs SendMail
Many mail services, such as Gmail, vigorously check for spam, and much of the spam you would otherwise receive simply bounces, rather than even making it to your spam folder!
To prevent this, it helps if the mail server you are sending from has valid MX and SPF records, although this is fairly technical for most people. However, because Gmail is fairly well known, many services do not bounce email origination from smtp.mail.google.com (Gmail). Therefore, you might benefit from setting up an account for your script to use on Gmail, and then using a third-party library to connect to the account and send/receive emails.
If you haven't looked into it, SwiftMailer allows you to send mail on behalf of a Gmail account using PHP.
I'm trying to email new registered users for email verification (PHP) but i don't get it, why would an email be sent to SPAM, i already checked out similar questions and all answers are about Headers,
It seems a bit complicated for me to get known to those headers and how are they being verified,
By sender website ? lets say i sent as user#google.com and the actual server domain is domain.com, how would it know? and is it one of the main reasons why it goes to spam ?
I am using VPS, does it has anything to do with it ?
I'm just trying to understand the clear/simple reasons of why would an email be checked as spam
and what if i sent from the server IP and not the domain itself
Most of the mail servers will do Reverse DNS lookup to prevent people from domain.com pretending to be from otherdomain.com. It will check if the IP address from which the email was sent resolves to the same domain name of the email sender. Yahoo and other big companies will also use DKIM to verify you.
Often your message can end up in Bulk/Spam if it doesn't have much content, or if you sent a lot of the same content to one server.
Here's a good article about what web developers should know about sending email that might help you understand the subject.
1) Check headers. You could use any email sending library such as PHPMailer (http://code.google.com/a/apache-extras.org/p/phpmailer/wiki/PHPMailer#Documentation_and_Resources)
2) Check hosting server. If your is using shared hosting then most probably it has been blacklisted by the email domain.
Configure an email address on your domain, replace me#mydomain.com with your newly created email address on your domain andid#hotmailOrgmail.com with your Hotmail/Gmail id in the following script.
Also replace Your Name with your name in the following script and test it on your server:
<?php
$myName = "Your Name";
$myEmailAddressonDomain = "me#mydomain.com";
$myPreferredEmailAddresson = "id#hotmailOrgmail.com";
$mail = $_POST['email_field'];
$clientName = $_POST['name_field'];
$subject = $_POST['subject_field'];
$text = $_POST['message_field'];
$headers = 'From: "$name" <$yourEmailAddressonDomain>'.PHP_EOL.'Reply-To: '.$_POST['mail'].PHP_EOL;
$to = '"$yourname" <$myPreferredEmailAddresson>';
$message = $text.PHP_EOL.PHP_EOL."---".PHP_EOL."From: ".$name." <".$mail.">";
/* Server-side form validations */
$err = "Error with ";
if (!checkLen($name)) {
$err.='Name';
} else if (!checkLen($mail) && !checkEmail($mail)) {
$err.='Email';
} else if (!checkLen($subject)) {
$err.='Subject';
} else if (!checkLen($text)) {
$err.='Message';
}
if (strlen($err)>11) {
echo $err.' field';
exit;
}
/* end validations */
elseif (mail($to, $subject,$message, $headers)) {
echo "<span style='color: #336600'>Your message has been sent.</span>";
} else {
echo "An error occurred, please try again.";
}
function checkLen($str,$len=1)
{
return isset($str) && mb_strlen(strip_tags($str),"utf-8") > $len;
}
function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[#][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}
?>
The email will land on your Hotmail/Gmail inbox (or any non-spam) folder via your domain's email address.
Note: Clicking Reply in the received email would show you the client's email address (as we have set in Reply-To header above)
Make appropriate changes and you are good to go.
as you are operating VPS, you may consider setting up DKIM and SPF on your server, they are used by mail services like Gmail to classify your server as a legitimate server.
I have a form that submits to PHP self. This script runs and says it is successful, but I do not receive an email.
if(isset($_POST['name']) and isset($_POST['email']) and isset($_POST['phone']))
{
//setup variables from input
$EMAIL = "anem#il.com";
$inEmail = $_POST['email'];
$subject = "Enquiry from ".$POST['name'];
$name = $_POST['name'];
//setup message
$message = "Enquiry from: ".$name."\nEmail: ".$inEmail."\nPhone: ".$phone."\n\nDeparture Date: ".$departureDate."\n\nreturnDate: ".$returnDate;
$message = wordwrap($message, 70);
//email enquiry details to site owner
if (mail($EMAIL, $subject, $message))
{
echo "Enquiry sent!";
} else
{
echo "fail!";
}
?>
The "Enquiry sent" message does appear.
I have postfix installed and I have also tried with sendmail installed. I have scanned local host using nmap and the smtp port is open.
Can anyone see any reason that the mail does not sent.
Check your mail log (usually /var/log/maillog). It would show the message arriving from PHP, and any delivery attempts/rejection notices from the MX of the receiver.
There a lot of possible reason that could explain why your email is sent and not received. Beside just setting up your SMTP server there are other things you need to do to make sure your email isn't just dropped before it reaches his destination.
You should take a look at this article that explains, what you should check :
http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html
In summary you need to :
Make sure the computer sending the email has a Reverse PTR record
Configure DomainKeys Identified Mail in your DNS and code
Set up a SenderID record in your DNS
Assuming that sendmail is working on your system, and that PHP is configured to use it correctly, try adding -f in the additional parameters, like this...
mail($EMAIL, $subject, $message, '-fYOURVALIDEMAILADDRESS#something.com'
This sets the envelope with a proper from address. See more on the PHP site: http://www.php.net/manual/en/function.mail.php#92528