PHP Mailing Code sending mail to spam/quarantine - php

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

Related

PHP mail send to multiple recipients, I must be doing something wrong

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

php email doesn't send from specified From: address

When I run this script to send an email, the email is being sent from serveradmin#myhosting. They say that the script isn't configured correctly.
I've changed the domain names and info shown below before posting here.
Is there really a problem with the scrip? The email sends, everything is fine.
It takes a bit long...don't know why, the only problem is it doesn't send from the domain I specified.
$to = $_POST['fes-email'];
$subject = 'TEST';
$body = 'TEST TEST';
$headers = 'From: NAME \(Info\) <name#domain.tld>' . "\r\n" .
'Reply-To: name#domain.tld' . "\r\n" .
'Return-Path: name#domain.tld' . "\r\n" .
'X-Priority: 1' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
mail($to, $subject, $body, $headers);
Try using quotes instead of escaping the parentheses:
$headers = 'From: "NAME (Info)" <name#domain.tld>' . "\r\n" .
You should remove the Return-path: header. This header is always recreated by the receiving server, using the envelope information sent via SMTP.
Have you tried putting just <name#domain.tld> in the headers for From?

Multiple and Separate Mail Functions PHP

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.

PHP - Not Sending Emails with Header Information

I am having a problem sending emails when I add header information.
However when I just remove the header parameter it works. What is wrong? Is it the code? Or some setting I need to change on the web server admin panel to say "Allow-Headers" or something?
I am trying to send to hotmail in case this has any relavance in determining the problem.
Any help would be greatly appreciated. Thanks.
Below Doesn't Send Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message, $headers);
?>
Below Sends Email:
<?php
$to = 'iputmyrealemailhere#hotmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com';
mail($to, $subject, $message);
?>
I use these headers in my php mailing function and it works well. Note: I also use a third party mail-routing service to avoid having my mails marked as coming from a spammy IP. You might want to look into that also.
$headers = 'From: '.$from.'#foo.net' . "\r\n" .
'Reply-To: '.$from.'#foo.net' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n";
I also use the optional fifth parameter to mail() to set the envelope address, e.g.:
$parameters = '-f '.$from.'#foo.net';
so the final call is:
mail($to, $subject, $message, $headers, $parameters);
You can just delete the "FROM:" from the headers list .. it prevents it in some hosts .But the real question then will be how ca I change the sent from email address to a specific email that I want

PHP from field when sending mail()

I'm using PHP's mail() function and noticing that my mail is being shown from being sent by 'My Website' in my inbox, but when I click on the actual email it shows it being sent from mywebsite#sitename.localdomain.
Ideally I'd like to have it say being sent from 'My Website', but the reply email being 'no-reply#mywebsite.com', and not to have it say anything about #sitename.localdomain.
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website' . "\r\n" .
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
Is this an issue that I need to fix in Apache, or can I modify the headers within PHP?
Try this:
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website <no-reply#mywebsite.com>' . "\r\n" . // <- change your email here
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
The Question and Answer #1 contains a serious security vulnerability -
$to = trim(strtolower($_POST['to']));
Will allow an attacker to use your website to email arbitrary spam and your site will be blocked from most search engines.
See
https://www.owasp.org/index.php/Top_10_2010-A1
My recommendation is to
Sanitize the to and from fields
Never ever ever copy the message in the post to the output unless carefully sanitized.

Categories