Mail, can't send to same email - php

For some odd reason if a user tries to send an email to themselves, the success function gets ran but the user never receives an email.
If $toAddress and $fromAddress are the same, user never receives the email. If they're different user does.
Have read a few questions on here, saying that if the email is on the same domain as the server it gets blocked for spam. But the users email isn't on the same domain as the server? Was testing this with my gmail account. Reply-to is not the email I'm actually using, it's just dumby text.
$to = $toAddress;
$subject = 'This is an email';
$message = $message;
$headers = 'From: '. $fromAddress . "\r\n" .
'Reply-To:do-not-reply#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-Type: text/html; charset=UTF-8';
if(mail($to, $subject, $message, $headers)){
echo '{"status": "success", "senderAddress": "' . $_SERVER['REMOTE_ADDR'] . '", "content": "' . $_POST['toAddress'] . '"}';
} else {
echo '{"status": "fail", "toAddress": ' . $toAddress . '", "fromAddress": "' . $fromAddress . '"}';
}

Exclude the headers in the mail() function and try it. The headers are triggering GMail's filtering system. If a mail is sent from Gmail, there is a certain Domain-Key based authentication that verifies the identity of the senders.
you might need to Create a TXT DNS record containing this text:
v=spf1 include:_spf.google.com ~all
in your DNS server, to authorize your domain sending email.

Due to filtering systems withing Gmail and Hotmail, when using yourself as the receiver and the from it was going directly into spam within Gmail and Hotmail. With Gmail if the two values are different it would go into your inbox while hotmail will still count it as spam.

Related

PHP won't send email with IP in it

So I'm sending email with confirmation link or link to change password. I had my website on one IP and now moved it to another IP. And now when I have in my link IP address same as where website is it won't send email, but if there is another IP it will. And on previouse IP address it worked fine.
I don't get it how can ip in mail affect sending actual mail.
Example of my code:
$subject="Pozabljeno geslo";
$message = '
Za spremembo geslo, kliknite na spodnjo povezavo:
http://xyz.x.xyz.3/~blabla/project2/index.php?stran=spremeniGeslo&email='.$email.'&hash='.$hash.'
';
$to = "$email";
$headers = "From: webmaster#example.com" . "\r\n" .
"Reply-To: " .$email . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject,$message,$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?

PHP: Gmail ignoring any email I send it via mail()

When using the below code I am able to send (and receive) email to my Yahoo account, but when sending to my Gmail account, nothing shows up
(and yes, I have monitored the Spam folder for over 4hrs - nothing!).
public function sendEmail($email_addy, $temp_pass)
{
$website_name = $this->website_name;
$message = <<<MESSAGE
Greetings!
Your password is:
$temp_pass
Your friends at: $website_name !
MESSAGE;
$headers = 'From: ' . $this->email_from . "\r\n" . 'Reply-To: ' . $this->email_from . "\r\n" . 'X-Mailer: PHP/' . phpversion ();
mail ( $email_addy, $this->email_subject, $message, $headers );
}
Any ideas why Gmail just deletes the email? I thought that the message body text might be too small so I even added to the message with no different results...

PHP mail from address header

I'm using PHP mail function to send messages from my web app.
I've created a table which holds the e-mail addresses and messages to send. The script fetches a certain number of messages and sends them.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=' . $charset . "\r\n";
$headers .= 'To: ' . $destName . ' <' . $destAddress . '>' . "\r\n";
$headers .= 'From:' . $fromName . ' <' . $fromAddress . '>' . "\r\n";
$headers .= "Reply-To: ". $fromName . ' <' . $fromAddress . '>' . "\r\n";
mail($destAddress, $subject, $msgBody, $headers);
My problem is that, even setting the FROM and REPLY-TO header, the address shown on the list of received messages is strange (not the one I've sent). See picture below,
But when I open the message, it seems all is OK, ie the sender is the one I've configured.
Can anyone help me?
If there would be nothing that shows that the "from" and "reply-to" field are different from the address from where the mail was sent, then everyone would be able to sent you a mail coming from for instance obama#whitehouse.org
If you want the email of your choice to be shown, you should use smtp, log in to the mailserver with the correct account, and sent the mail. This will cause the mail to be verified and trusted.
http://www.9lessons.info/2009/10/send-mail-using-smtp-and-php.html
This is probably an issue with the web interface of dispostable.com which does not show the contents of the "from" but the address of the sending mailserver in the overview. This might be a security measure. Dis you try to send to a "normal" address?
By the way, the address in "from" should be resolvable to the server from where it was sent. For example a mail from admin#abcdefg.com should come from the server ip of abcdefg.com. Else it will be calssified as spam by some mail clients or mail servers.

PHP Mailing Code sending mail to spam/quarantine

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

Categories