Is my $headers and or second mail() function incorrect or improper? My page has a form that when you fill out will send an email to the recipient, then a second one to via a text message (many carriers has a text to email feature). When I submitted the form the first mail() function works, but the second one doesn't. Any ideas? Also, I'm doing this because I want it to send an email and a text message (I thought this was a great idea) so that the recipient is notified that there's an email that needs his/her attention.
Here's what I mean.
// HTML FORM here, collects just name, email, subject line, message
// When the form is submitted it does this...
$to = "recepient#email.com";
$to_sms = "recepienttextnumber#tmomail.net";
$subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING)." - FORM";
$headers = 'MIME-Version: 1.0' . "\r\n" .
'Content-type:text/html;charset=iso-8859-1' . "\r\n" .
'From: noreply#email.com' . "\r\n" .
'Reply-To: info#email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$body = "
<html>
<p>This is an automatic email notification. <strong>Please do not reply to this email</strong></p>
<p>You received a message from ". $name . " that needs your attention ASAP.!</p>
<p>Client name: ".$name."<br />
Client phone: ".$phone."<br />
Email: ".$email."<br />
About: ".$_POST['subject']."<br />
Message: ".$message."</p>
</html>";
$body_sms = "Great news! ".$name." has contacted you via the FORM. Check your email now.";
// Send Email & Text Notification
//Here sends out the form via email
mail($to, $subject, $body, $headers);
//alternatively a second message is sent to another
mail($to_sms, $subject, $body_sms, "From: FORM");
//Echos a thank you.
I suggest you make a copy of your $headers and name it $headers2 and use
mail($to, $subject, $body_sms, $headers2);
that may be the problem.
Related
I read the other questions and solutions... which is why I'm frustrated. I didn't code this app, but I'm trying to retrofit it.
Currently it sends a confirmation email to the email address that gets entered by the customer in the field. When I comment out the mail($to,... part at the bottom, it breaks the confirmation email functionality, so I know I'm in the right place in the code.
I just want a duplicate email sent to my master email address. I thought if I just put another mail command under the functional one, but specified a static address instead of the $to var it would work... but it doesn't. I couldn't get the CC header functionality to work either based on other questions, so I thought just sending a duplicate email to another address would work just fine.
Here is the working code:
$sq2 = myQuery(" select * from admin ");
$dat2 = mysql_fetch_object($sq2);
$from = "reservations#duelingpianopiano.com";
$to = $email;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "From: $from" . "\r\n";
$headers .= "Reply-To: $from" . "\r\n";
/*$headers = "From: $from" . "\r\n" .
"Reply-To: $from" . "\r\n" .
'X-Mailer: PHP/' . phpversion();*/
mail("vmvijitha#gmail.com", $subject, "sendemailtemplate($templateid,$tid,$userid,$modification)".$mailcontent, $headers);
//return;
mail($to, $subject, $mailcontent, $headers);
I feel like if I should just be able to add this line at the bottom to send the exact same email confirmation redundantly to my master email address for safe keeping.
mail("reservations#duelingpianopiano.com", $subject, $mailcontent, $headers);
Note: I think this line is an artifact from the original developer, and I can't tell whether it's working or not.
mail("vmvijitha#gmail.com", $subject,...
What am I assuming wrong?
insert multiple addresses using comma-separator in single variable.
$email_to = "xxx#one.com, xxx#two.com, xxx#three.com"
mail($email_to, $subject, $mailcontent, $headers);
I am trying to get contact form details through mail. But failed to do so using mail() function. here's my code.
if(isset($_POST['rqsubmit'])) {
$name = htmlspecialchars($_POST['Field1']);
$email = trim($_POST['Field2']);
$phone = trim($_POST['Field3']);
$msg = strip_tags($_POST['Field4']);
//echo $name." ".$phone." ".$email." ".$msg;
$to = 'gowtham#gmail.com';
//$from = $email;
$subject = "Software Development";
$message = "Name:".$name."<br/>Phone".$phone."<br/>Message:".$msg;
//echo $message;
$semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
//echo $message;
$headers = "From: xyz#gmail.com". "\r\n".
'Reply-To: xyz#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$ok = #mail($to, $subject, wordwrap($message, 70, "\r\n"), $headers);
if ($ok) {
echo "<p>Thank you for contacting us! !!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
} else {
echo "mail not sent";
}
I would like to know where i am going wrong. Any help would b highly appreciated. thank you!
Add:
'X-Mailer: PHP/' . phpversion();
to:
$headers
Perhaps it's being rejected due to the lack of a sender email address.
Put your own email address in the From: header, and add a Reply-To: header containing the sender's address.
Can I just point out that you need to check the form data thoroughly before putting it into an email. For example, I could quite easily send emails all over the place by setting Field2 to something like blah#example.com\nBcc: spam1#spam.com, spam2#spam.com, ....
EDIT:
Sorry, my mistake — you did add a From header. However, it's quite likely that your mail server is configured to reject emails where the sender address is not on its list of approved senders. That's why you need to put your own address in the From: header, and the sender's address in the Reply-To: header.
EDIT 2:
Also, what on earth are you doing with $mime_boundary? As far as I can tell, you're not sending a valid MIME message.
The title explains itself. It is a website for in-house employees to buy and sell from each other. Its based solely around Microsoft Outlook emailing addresses. All the emails are supposed to be sent from the seller's email as they post items. Except when I enter <php phpinfo(); ?> on the action php page it tells me that the sendmail_from attribute thing is sending from a bogus email on the server. It seems to be the automatic email for the php script to send from. This may be why the emails are getting sent to spam, because the email is not valid. Also, I read online about having full and valid headers but most headers seem optional and i cant find anywhere that explains optimal headers. My mailing code:
//send approval email to the approver
$from = isset($_POST['from'])? $_POST['from']:1;
$message = isset($_POST['message'])? $_POST['message']:1;
$message = $message . '<a href="http://dev-corkboard/newapproval.php?id='
.$result[0][0].'"> Click here to approve website post.</a>';
// In case any of our lines are larger than 70 characters, we should use
// wordwrap()
$message = wordwrap($message, 70);
$to = 'clehane#eatonvance.com';
$replyto = isset($_POST['replyto'])? $_POST['replyto']:1;
$subject = isset($_POST['subject'])? $_POST['subject']:1;
$headers = "MIME-Version: 1.0" . "\r\n" . 'From: "'.$from.'"' . "\r\n" .
'Reply-To: "'.$replyto.'"' . "\r\n" .
'Content-Type:text/html;charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
//test message for email
}
header ("location: newindex.php"); `
Any ideas?
And bam! Solved it, needed to put email addresses as such:
$from = 'MyName <myemail#mycompany.com>';
And I also included these headers:
"X-Priority: 0\r\n".
"X-MSMail-Priority: Normal\r\n".
"X-Mailer: mycompany.com
I have a registration page on a site I'm working on. When the person registers for an account it sends an email to the registrants email address with a confirmation link to activate the persons account. The problem is that the "from" email address the registrant receives the email from is: myhostingaccountusername#myhostingprovider###.com.
I want to be able to have the email be: no-reply#mydomain.com.
I'm using PHP and Mysql along with html for the site.
here is my code for sending the email.
// Send the email:
$body = "Thank you for registering at My site. To activate your account, please click on this link:\n\n";
$body .= BASE_URL . 'activate.php?x=' . urlencode($e) . "&y=$abc";
mail($trimmed['email'], 'Registration Confirmation', $body, 'From: noreply#mysite.com');
How do I do this?
When sending the e-mail to your "registrant" you should set the headers of the mail function in PHP to contain "From" field
for example :
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: no-reply#example.com' . "\r\n" .
'Reply-To: me#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
?>
Have you set the From: header for the e-mail?
See http://php.net/manual/en/function.mail.php, example #2.
I am using a simple HTML form for an event registration and I would like to send a PHP confirmation email to the registrant with the same information that is going to the administrator.
Here are the details:
$emailFromName = $_POST['name'];
$emailFrom = $_POST['email'];
$emailFromPhone = $_POST['phone'];
I would like to use the value from $emailFrom in the following email address to:
$emailTo = "name#domain.com", \"$emailFrom\";
edit: Added new configuration:
$emailHeaders = 'From: "Conference" <noreply#conference.org>' . 'CC: . $emailFrom .';
This obviously doesn't work, but you get the idea of what I am trying to.
Thanks!
You will need to add headers to the mail function...
for example:
$headers = 'From: Family History Conference <noreply#familyhistoryconference.org>' . "\r\n" .
'Reply-To: noreply#familyhistoryconference.org' . "\r\n" .
'CC: ' . $emailFrom . "\r\n";
and then
mail($to, $subject, $message, $headers);
References:
PHP Mail Function
You put "From: $name <$emailFrom>" in the additional parameters of the mail() function:
http://php.net/manual/en/function.mail.php
So, basically you want to CC a copy of the message to the user as well as the administrator?
It depends on which PHP library you're using to send it. If you're using the default PHP mail() function, you'll need to add additional headers:
// Additional headers
$headers .= 'Cc: ' . $emailFrom . "\r\n";
// Mail it
mail('admin#email.com', $subject, $message, $headers);