PHP Mail Function not sending from Gmail Addresses - php

I'm trying to get this contact form working and it doesn't seem to be able to send with headers saying it is from a gmail address I feel like yahoo addresses were also in the mix of ones that didn't work. Here is the code that seems like it would matter to this. If the host matters I am on Dreamhost. Let me know please.
if(!is_array($contact_information_type))
{
$contact_information_type = Array();
}
if($_POST){
$contact_name = trim(stripslashes($_POST["contact_name"]));
$contact_company = trim(stripslashes($_POST["contact_company"]));
$contact_address1 = trim(stripslashes($_POST["contact_address1"]));
$contact_address2 = trim(stripslashes($_POST["contact_address2"]));
$contact_city = trim(stripslashes($_POST["contact_city"]));
$contact_state = trim(stripslashes($_POST["contact_state"]));
$contact_zip = trim(stripslashes($_POST["contact_zip"]));
$contact_country = trim(stripslashes($_POST["contact_country"]));
$contact_phone = trim(stripslashes($_POST["contact_phone"]));
$contact_fax = trim(stripslashes($_POST["contact_fax"]));
$contact_email = trim(stripslashes($_POST["contact_email"]));
$contact_comments = trim(stripslashes($_POST["contact_comments"]));
if($contact_name == ""){ $errors_array[] = "Name is required."; }
if($contact_company == ""){ $errors_array[] = "Company name is required."; }
if($contact_city == "") { $errors_array[] = "City is required."; }
if($contact_state == ""){ $errors_array[] = "State is required."; }
if($contact_country == "") { $errors_array[] = "Country is required.";}
elseif($contact_country == "United States" )
{if($contact_zip != "" && !preg_match("/(^\d{5}$)|(^\d{5}-\d{4}$)/", $contact_zip)){ $errors_array[] = "Incorrect Zip. (e.g. 60660 or 60660-1234)"; };}
elseif($contact_country == "Canada" ){if($contact_zip != "" && !preg_match("/^[ABCEGHJ- NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$/i", $contact_zip)){ $errors_array[] = "Incorrect Zip. (e.g. M4C 1B5 or M4C1B5)"; };}
else {;}
if($contact_phone == ""){ $errors_array[] = "Phone is required."; }
if($contact_phone != "" && !preg_match("/(^\d{3}-\d{3}-\d{4}$)| (^\d{10}$)/", $contact_phone)){ $errors_array[] = "Incorrect Phone. (e.g. 123-123-1234)"; }
if($contact_fax != "" && !preg_match("/(^\d{3}-\d{3}-\d{4}$)|(^\d{10}$)/", $contact_fax)){ $errors_array[] = "Incorrect Fax. (e.g. 123-123-1234)"; }
if($contact_email == ""){ $errors_array[] = "E-mail is required."; }
if($contact_email != "" && !preg_match("/^[a-zA-Z0-9_.-]+#[a-zA-Z0-9-]+\. [a-zA-Z0-9-.]+$/", $contact_email)){ $errors_array[] = "Incorrect E-mail. (e.g. youremail#domain.com)"; }
if($contact_comments == ""){ $errors_array[] = "Comments are required."; }
if(sizeof($errors_array) == 0){
$contact_information_type = implode(", ", $contact_information_type);
$email_message = <<<MESSAGE
The contact form on www.rotaryvalve.com has been filled out with the following information:
Name: ${contact_name}
Company: ${contact_company}
Address 1: ${contact_address1}
Address 2: ${contact_address2}
City: ${contact_city}
State: ${contact_state}
Zip: ${contact_zip}
Country: ${contact_country}
Phone: ${contact_phone}
Fax: ${contact_fax}
E-mail: ${contact_email}
Comments/Products of Interest: ${contact_comments}
MESSAGE;
$email_adds = array("sales-team#wmwmeyer.com", "dan#danbaran.com");
$email_from = $contact_email;
$email_subject = "Customer Request/Comment";
foreach($email_adds as $email_to){
mail ($email_to, $email_subject, $email_message, "From: ".$email_from." <".$email_from.">");
}
essentially if the contact_email filled out on the form(code not included sorry didn't think you'd need it but let me know if you do) is a gmail account it doesn't seem to send it please help me out on this one.

Is the problem not being sent, or not being received. I'm pretty sure that the problem is not the email being sent, but what happens when it gets received by the receiver's email service. It may be classed as spam, because they can see it is not sent from the GMail mailservers.

The email may be classed as spam by the receiving server or client, due to SPF records on the gmail.com domain that will most likely mark the emails as spam.
You would however be able to send the email with a 'Reply-To' header of the email entered in the contact form. This would give the email a better chance of getting past spam filters, and if the recipient hits the "Reply" button in their client, the email will default to being sent to this address.

Related

checking if email and confirm email fields are the same using php

I would like to confirm that the email field and confirm email field match each other in my html form before submitting the form to the database, i have done the following but it doesn't seem to work:
<?php
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$_SESSION['error'][] = "Invalid email address";
}
if ($_POST['email'] != $_POST['confirmemail']) {
$_SESSION['error'][] = "Email addresses do not match";
}
else {
this is followed by the script to submit the form to the database which works fine. Any suggestions would be welcome, many thanks
There might be whitespace issue causing your comparison to fail. try trimming your inputs before comparison.
$email = trim( $_POST['email'] );
$confirmEmail = trim( $_POST['confirmemail'] );
if ($emsil != $confirmEmail ) {
$_SESSION['error'][] = "Email addresses do not match";
}

Error when no mail is inserted in form, using phpmailer

I am having trouble with a form, when the user mail is not inserted, it always return the error message "Invalid address: email". I understand $reg_email variable is being used in other functions to send the mail to the user, so I realize I must write a condition that says that when the reg_email variable is empty, it must return a value that wont cause that error. But I dont know how to translate that logic to PHP. What should I do?
<?php
ini_set('display_errors', 1);
session_start();
if($_SESSION['input_flag']) {
unset($_SESSION['input_flag']);
}else{
header('location: /');
}
$path = realpath(dirname(__FILE__) . '') . "/../";
include_once($path.'app_config.php');
include($path.'libs/meta.php');
//設定
require('./jphpmailer.php');
$script = "index.php";
$gtime = time();
$reg_name = isset($_POST['f_name']) ? htmlspecialchars($_POST['f_name']): "";
if (isset($_POST['f_company']) && !empty($_POST['f_company'])) {
$f_company .= "■会社名"."\r\n" . $_POST['f_company'];
}
$f_adress = isset($_POST['f_adress']) ? htmlspecialchars($_POST['f_adress']): "";
$f_select = '';
if (!empty($_POST['select'])) {
foreach ($_POST['select'] as $key => $value) {
$f_select .= "設置されている消防設備"."\r\n" . $_POST['f_select'];
}
}
$f_tel = isset($_POST['f_tel']) ? htmlspecialchars($_POST['f_tel']): "";
// $reg_email = isset($_POST['f_mail']) ? htmlspecialchars($_POST['f_mail']): "";
if (isset($_POST['f_mail']) || !empty($_POST['f_mail'])) {
$reg_email .= "email"."\r\n" . $_POST['f_mail'];
}
$f_select2 = '';
foreach ($_POST['select2'] as $key => $value) {
$f_select2 .= $value."\r\n";
}
$f_request = isset($_POST['f_request']) ? htmlspecialchars($_POST['f_request']): "";
$aMailto = array(
"xxxxxx"
);
$from = "xxxxxx";
$fromname = '';
$subject1 = 'test';
$subject = 'test';
$entry_time = gmdate("Y/m/d H:i:s",time()+9*3600);
$entry_host = gethostbyaddr(getenv("REMOTE_ADDR"));
$entry_ua = getenv("HTTP_USER_AGENT");
$msgBody = "";
$msgBody .= "
■お名前
$reg_name
$f_company
■建物の所在地
$f_adress
$f_select
■お電話番号
$f_tel
$reg_email
■ご希望の連絡方法
$f_select2
■お問い合わせ内容
$f_request
";
//お問い合わせメッセージ送信
$subject = "ホームページからお問い合わせがありました";
$body = "
登録日時:$entry_time
ホスト名:$entry_host
ブラウザ:$entry_ua
ホームページからお問い合わせがありました。
$msgBody
";
//Message for the user
$subject1 = "お問い合わせありがとうございました";
$body1 = "
$reg_name 様
$msgBody
";
// メール送信
mb_language("ja");
mb_internal_encoding("UTF-8");
$fromname = "";
//お客様受け取りメール送信
$email1 = new JPHPmailer();
$email1->addTo($reg_email);
$email1->setFrom($from,$fromname);
$email1->setSubject($subject1);
$email1->setBody($body1);
//if($email1->send()) {};
//Anti spam advanced version 2 start: Don't send blank emails
if( $reg_name <> "" && $reg_email <> "" ) {
//Anti spam advanced version 1 start: The preg_match() is there to make sure spammers can’t abuse your server by injecting extra fields (such as CC and BCC) into the header.
if( $reg_email && !preg_match( "/[\r\n]/", $reg_email) ) {
//Anti spam part1: the contact form start
if($reg_url == ""){
// then send the form to your email
if($email1->Send()) {};
} // otherwise, let the spammer think that they got their message through
//Anti spam part1: the contact form end
}//Anti spam advanced version 1 end
}//Anti spam advanced version 2 end: Don't send blank emails
//メール送信
$email = new JPHPmailer();
for($i = 0; $i < count($aMailto); $i++)
{
$email->addTo($aMailto[$i]);
}
$email->setFrom($reg_email, $reg_name."様");
$email->setSubject($subject);
$email->setBody($body);
//if($email->Send()) {};
//Anti spam advanced version 2 start: Don't send blank emails
if( $reg_name <> "" && $reg_email <> "" ) {
//Anti spam part1: the contact form start
if($reg_url == ""){
// then send the form to your email
if($email->Send()) {};
} // otherwise, let the spammer think that they got their message through
//Anti spam part1: the contact form end
}//Anti spam advanced version 2 end: Don't send blank emails
?>
It's because you're doing this:
$reg_email .= "email"."\r\n" . $_POST['f_mail'];
the word email, followed by a line break, followed by an email address is not itself a valid email address, so will be rejected with the error you're seeing. You're also appending to a variable that has not yet been defined. Do this instead:
$reg_email = $_POST['f_mail'];
I'm also puzzled by this:
$email->addTo($aMailto[$i]);
PHPMailer uses addAddress, not addTo, so unless that's a new method or alias in your JPHPmailer subclass, it's wrong.
Also, don't do this:
$email->setFrom($reg_email, $reg_name."様");
This is forgery and will result in your message being bounced or spam filtered by recipients. Do this instead:
$email->setFrom('myemail#example.com', $reg_name."様");
$email->addReplyTo($reg_email, $reg_name."様");
That is, send from your own address and use the submitter's address as a reply-to.

Not able to send mail on Godaddy webmail using php contact form

I have created one contact form in php, its perfectly working for gmail but while I am trying to send mail on godaddy webmail status showing successfully sent, But mail not coming in my godaddy webmail box.
Here is my code.
<?php
if(isset($_POST['Submit_mail'])){
$name=trim($_POST["name"]);
$number=trim($_POST["number"]);
$email=trim($_POST["email"]);
$msg=trim($_POST["msg"]);
$catalogue=trim($_POST["catalogue"]);
if($name == "" ) {
$error= "error : You did not enter a name.";
$code= "1" ;
}
elseif($number == "" ) {
$error= "error : Please enter number.";
$code= "2";
}
//check if the number field is numeric
elseif(is_numeric(trim($_POST["number"])) == false ) {
$error= "error : Please enter numeric value.";
$code= "2";
}
elseif(strlen($number)<10) {
$error= "error : Number should be 10 digits.";
$code= "2";
}
//check if email field is empty
elseif($email == "" ) {
$error= "error : You did not enter a email.";
$code= "3";
} //check for valid email
elseif(!preg_match("/^[_\.0-9a-zA-Z-]+#([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {
$error= 'error : You did not enter a valid email.';
$code= "3";
}
elseif($msg == "" ) {
$error= "error : Please enter Product Description.";
$code= "4";
}
else{
$message='my message ';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
if(mail('mywebmailid','You have a new quote request from client',$message,$headers))
{
//header("Location:index.php?status=true");
echo "Success";
}
else
{
//header("Location:index.php?status=false");
echo "fail";
}
}
}
?>
Godaddy seems to have broken their php mail() command in December 2016. I am trying to solve the problem myself. It worked until mid December, while I was away on holiday, and I just was informed by my staff no emails come through anymore. No errors, php mail() responds with success.
Godaddy changed something and they have not told me what they changed! Annoying, they do this too much, likely moving to a new host soon as my terms are up.
If I can identify the problem I will post it here for you.
What does still work is the godaddy formmail and gdform functions that are built into your hosting account. These are quite ugly, and cannot be customized and only one email address will work.

How to add a field in php email form?

I need to add one more field in the php email form below, but I don't know much about php.
I need to add a field for a phone number, and I can see that the new field needs to be entered into the function build_message near the end of the formemail.php script. I've added $phone, but no luck in getting it to work and I get no error messages.
The html for the whole form is
<form action="formemail.php" method="post">
<input type="text" name="name" value="name" id="name" size="35" />
etc.... and the phone field is:
<input type="text" name="phone" value="Phone" id="phone" size="35" /> </form>`
The php form:
$my_email = "senttoemail#gmail.com";
$continue = "/";
$errors = array();
if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
function recursive_array_check_header($element_value)
{
global $set;
if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc:)/i",$element_value)){$set = 1;}}
else
{
foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}
}
}
recursive_array_check_header($_REQUEST);
if($set){$errors[] = "You cannot send an email header";}
unset($set);
if(isset($_REQUEST['email']) && !empty($_REQUEST['email']))
{
if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['email'])){$errors[] = "Email address may not contain a new line or a colon";}
$_REQUEST['email'] = trim($_REQUEST['email']);
if(substr_count($_REQUEST['email'],"#") != 1 || stristr($_REQUEST['email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("#",$_REQUEST['email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
}
if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
function recursive_array_check_blank($element_value)
{
global $set;
if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
else
{
foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
}
}
recursive_array_check_blank($_REQUEST);
if(!$set){$errors[] = "You cannot send a blank form";}
unset($set);
if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
$message = build_message($_REQUEST);
$message = stripslashes($message);
// $phone = stripslashes($phone);
$subject = "Webmail";
$headers = "From: " . $_REQUEST['email'];
mail($my_email,$subject,$message,//$phone, $headers);
Where did you get this script from? The $message variable is the body of your email and it looks like it's created by running the build_message function. You can get rid of your $phone variable as it appears as if the script automatically finds all the form fields by looking through the input fields ($_REQUEST). I ask where you got the form from to see if there's some sort of simple documentation about this and maybe you need to add something to your form that tells the script what fields to add to your message

PHP Email Form Sending Random Text

I did a webpage for a client that involved a series of text boxes asking for specific information such as a person's name, e-mail address, company, etc. Along with a button that would e-mail the information to my client. Whenever I tested the button it seemed to work perfectly, I uploaded the page and thought I was done. But, the other day my client got this email from the site:
Name: rfhopzdgmx rfhopzdgmx
Email: envlxw#lnlnsm.com
Company: zUDXatAfoDvQrdH
Mailing Address:
AaSsXklqpHIsoCNcei
gXsimMPRBYZqq
vGLvZraZNdpOAV, ChsmuibE PoKzaSCubXPRI
Home Phone: CIJbIfjMfjIaTqAlD
Work Phone: JFLZBOvru
Cell Phone: XlFJTTFGiTTiiFQfy
Fax: UEJMOVZodWPkKxew
Comments:
sPvSCE hgetwoguderu,*
[url=http://atyktjlxcznl.com/]atyktjlxcznl[/url],
[link=http://nudvfcehwpyg.com/]nudvfcehwpyg[/link], http://lvvwkbzbhnzp.com/
Note: The * line contained HTML link code, I just don't know how to get this site to show it.
Here is the PHP code in the site for the e-mail button.
<?php
//This Sends A Formatted Text Email Using The Text Boxes
if ($_POST['submit']){
//This Gets The Form Data
$fname = $_POST['fName'];
$lname = $_POST['lName'];
$email = $_POST['email'];
$company = $_POST['co'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$homep = $_POST['homeP'];
$workp = $_POST['workP'];
$cellp = $_POST['cellP'];
$fax = $_POST['fax'];
$comments = $_POST['txaOutputField'];
//echo "<script language = 'javascript'>alert('YAY');</script>";
if ($fname && $lname && $email && $comments){ //Check If Required Fields Are Filled
//This Sets The SMTP Configuration In php.ini
ini_set("SMTP", "smtp.2ndsourcewire.com");
//This Replaces Any Blank Fields With 'None's
if ($company == ""){
$company = "None";
}
if ($address1 == ""){
$address1 = "None";
}
if ($city == ""){
$city = "None";
}
if ($state == ""){
$state = "None";
}
if ($zip == ""){
$zip = "None";
}
if ($homep == ""){
$homep = "None";
}
if ($workp == ""){
$workp = "None";
}
if ($cellp == ""){
$cellp = "None";
}
if ($fax == ""){
$fax = "None";
}
//This Creates The Variables Necessary For The Email
$to = "CLIENT EMAIL WHICH I'M CENSORING";
$subject = "Email from 2ndSourceWire.com";
$from = "From: noreply#2ndsourcewire.com";
$secondEmail = "MY EMAIL WHICH I'M ALSO CENSORING";
if ($address2 == ""){
$body = "Name: $fname $lname\n".
"Email: $email\n".
"Company: $company\n\n".
"Mailing Address:\n".
"$address1\n".
"$city, $state $zip\n\n".
"Home Phone: $homep\n".
"Work Phone: $workp\n".
"Cell Phone: $cellp\n".
"Fax: $fax\n\n".
"Comments:\n".
"$comments";
}
else {
$body = "Name: $fname $lname\n".
"Email: $email\n".
"Company: $company\n\n".
"Mailing Address:\n".
"$address1\n".
"$address2\n".
"$city, $state $zip\n\n".
"Home Phone: $homep\n".
"Work Phone: $workp\n".
"Cell Phone: $cellp\n".
"Fax: $fax\n\n".
"Comments:\n".
"$comments";
}
//This Sends The Email
mail($to, $subject, $body, $from);
mail($secondEmail, $subject, $body, $from);
echo "<script language = 'javascript'>alert('The email was sent successfully.');</script>";
}
else {
//The Required Fields Are Not Filled
echo "<script language = 'javascript'>alert('Please fill your first name, last name, email address, and your comment or question.');</script>";
}
}
?>
I'm a little dumbfounded on how this happened, the client mentioned a couple e-mails of this, so I don't think it is a random glitch. Also, the e-mail address was formatted like an e-mail address, so someone or some program was interpreting the labels next to each text box. I also noticed that the first and last names entered are the same word, even though they were in different text boxes, I'm thinking its some spam program, but wouldn't they try to advertise something and make money, rather than just spouting out random text? Also, the comments section makes no sense to me at all, the links goto nowhere and they're all perfectly formatted, a random person just screwing around wouldn't know those tags, and a programmer doing it wouldn't bother with it, but also neither would a program.
I have no idea what caused this or how to fix it, I'm drawing a blank here. Anyone have any ideas?
A spammer/bot entered duff data into your page and you dutifully sent it on in your application.
Why do you think this is a mystery?
add a CAPTCHA to stop it happening. If you dont what to write your own you can use reCAPTCHA
even a simple question like "are you a human Y/n?" or "2+2?" will stop the bot,
also using some js to set an hidden value on submit and check for that on the server.
some validation on $email and $phone would be nice to have.
Instead of making people try to read CAPTCHAs, I like to have four text boxes in a row and ask the user to check two random ones (e.g. "Please check the first and third boxes") and make sure those are the only two checked in the validation.

Categories