I am trying to send a mail with php. I watched in the internet to find a solution and I found diferent ways but not one helped me. When I come to the code where it should send the mail I got following error:
mail(): SMTP server response: 530 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [AM4PR08CA0065.eurprd08.prod.outlook.com]"
mail call:
$mailAdr = "name#company.ch";
$subject = "subject";
$msg = "message!";
$header = 'FROM: My WebSite <name#company.ch>';
mail($mailAdr, $subject, $msg, $header);
I set the right smtp and port. Can anyone tell me what I am doing wrong?
I think you have to add your FROM header that is missing in your code.
<?php
$header = 'From: My Website <info#example.com>' . "\r\n";
mail($empfaenger, $betreff, $nachricht, $header);
?>
It's very strange and I don't know why, but when I pass my '$to' string to the mail() function, for some unknown reason, It sends to all users in the database, instead of just those being passed into the $to string.
EXAMPLE: I pass the following it.
'User1 , Mod1 '
Result: On the positive side, all those listed receive emails as intended. But so does everyone else which makes me feel like i'm spamming some folks unintentionally with notices they don't want/didn't ask for/have nothing to do with them.
'User1 <user1#example.com>, User2 <user2#example.com>, User3 <user3#example.com>, User4 <user4#example.com>, User5 <user5#example.com>, Mod5 <mod5#example.com>'
I have been through my script several times, and I have var_dump() and xDebugged the $to variable just before and after 'Mail()' is called, and the string shows only the people I expect for the mail function to send to, yet it still sends too all users. I am using php 5.6 currently on DreamHost. It works in my local host (Ampps), but when i go live, its very unexpected results in which everyone is, as previously mentioned, received the email notifications.
This is how I set up the variables to send via mail()
// To send HTML mail, the Content-type header must be set
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
// Additional headers
$headers[] = 'To: ' . $to;
$headers[] = 'From: myDomain - ' . $ttl . ' <noreply#myDomain.com>';
$headers[] = 'Cc: ' . MOD_EMAILS;
$headers[] = 'Bcc: xxxxxxx#gmail.com';
//var_dumped() //i var_dump here, string was as expected
// Mail it
mail($to, $subject, $message, implode("\r\n", $headers));
//var_dumped() //var_dump here, string was as expected
Does anyone have/have had an experience like this? Or an idea of how to resolve it? I'm a newbie and trying to build my own CMS as a means of teaching myself to write PHP and stuff.
Thank you.
I solved the issue, which had as I thought nothing to do with he database or any of the sql calls. Rather, it had to do with the fact that I had the $to variable both in the $headers and then also in the actual mail() function call, along with the $variable. By commenting out the $headers[] = $to, the issue was solved.
I wrote a PHP script to send emails.
My script is like this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: abc#yahoo.com' . "\r\n";
// Email Variables
$toUser = "someone#yahoo.com"; // recipient
$subject = "testing"; // subject
$body = "<html><body><p>
Example of including an image via html \<img\> tag:
<br>
<img src='../images/profile.jpg'>
<br>
My new picture
<br></p></body></html>"; // content
if (mail($toUser,$subject,$body,$headers)) {
echo "sent";
} else {
echo "failed";
}
Well, of course I use a valid email address for sender and receiver. I did receive the email, but it goes to junk mail. So I went for google research. Is it because of my "header" script problem? If it isn't, then what could cause my script to send a junk mail? Any solution?
Please try this:
$headers ="From:<$from>\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";
mail($to,$subject,$body,$headers,"-f$from");
Perhaps the problem is that yahoo uses domainkeys verification, which will likely fail for your application given that the mail is not actually coming from yahoo's servers.
When I've once had a similar problem I looked at the headers and found out that my host uses SpamAssassin. So I googled for 'SpamAssassin score' and found a multitude of information on how to incorrectly (and thus correctly) form an email.
For example: SpamAssassin score list
1. Check mail content
As others have hinted it is probably marked as spam because your mail looks like spam.
I am not sure if you the script that you have posted is the actual one that you are testing.
If it has the actual mail body & headers, then running this message through a standard installation of SpamAssassin gives it a spam score of 4.9
X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_50,HTML_IMAGE_ONLY_04,
HTML_MESSAGE,MIME_HTML_ONLY,NO_DNS_FOR_FROM,NO_RELAYS autolearn=no
version=3.2.5
Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.
2. Mail server's IP
Another aspect worth checking will be the IP address of your mail server. Any mail originating from dynamic IP addresses will potentially be considered as SPAM.
3. Blocklists
Also check if your IP address is listed in one of the block lists. To start with please check your IP address with http://www.spamhaus.org/lookup.lasso.
Use mxtoolbox.com to check the servers IP to be blacklisted or not. As well this website can help you with a couple of email related checks.
Of course there are a long list of checks running inside spam filters. As already suggested, check the email headers for details about the spam filters rating of the spam email.
Hope that helps!
**This Works Perfectly fine for me**
$to="reciever#reciever.com";
$subject="This is Your Message";
$from = 'Sender <noreply#sender.com>';
$body='Hi '.$name.', <br/><br>Now You can See Yor main in inbox';
$headers = "From: " .($from) . "\r\n";
$headers .= "Reply-To: ".($from) . "\r\n";
$headers .= "Return-Path: ".($from) . "\r\n";;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
mail($to,$subject,$body,$headers);
I was having the same problem:
The problem is that when you specify content-type before the "From:" part , the mail comes as a spam.
But if you specify "From:" before the content part it comes as a normal mail and makes you smile and curious.
As schnalle said, one problem surely is that the smtp server that you use to send the email and the one thet you specify as From, is different.. the from's domain whould be the same that the server youre running on.
So, you can use the yahoo server to send the email (check if they allow the smtp remote connection, but i guess they do) connecting by smtp, and this will solve 1 problem.
Another one is the html contents without the alternative plain text contents, but, this one is less important.
I suggest you phpMailer, free and open-source php class to send email, easly to use (i use it event o send mail through gmail server)
On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
Make sure you send your e-mails from an existing account on your server/domain.
Make sure you have the reply-to address in your header.
These are the basic things you can try.
if your website domain is mydomain.com then in From headers make sure to use someone#mydomain.com
Remove the Content-type: text/html and add $headers .= "X-Priority: 2\nX-MSmail-Priority: high"; to get rid of Spam. This method has been tried and tested.
the problem is, the server you're sending the mail from is not a yahoo server. most spam filters check if they match, otherwise it would (and is - or was) possible to easily fake the sender. ever wondered why you get spam from bill.gates AT microsoft.com or your own mail address?
You've got two solutions:
use Yahoo's SMTP using abc#yahoo.com credentials to send mail from abc#yahoo.com;
use other from, with your own domain;
You can try the mail class and test file that I have created here. I have tested the files and can send emails to my hotmail and gmail under a different mail name. The main reason why the emails are mark as junk is because the structure (both header and message) is not correctly done. In most cases, it is the line feed that is causing the problem.
I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)
You can check the files here..
Why the mail function not sending mail to me ,Could any one please help me ?
Here i have wrote script to mail sending.
Is there any other settings to send mail.
But the mail function printing always "Success" , but the mail not received to me.
$Msg = "Your Suggestion is saved successfully. Please wait for admin approval";
$subject="New Suggestion Posted - Waiting for approval";
//$email_id = 'bajrang.lal#sunarctechnologies.com';
$email_id = 'bajrang.lal#sunarctechnologies.com';
$mail_msg="Hello Admin,<br><br>New Suggestion Posted. Waiting for approval.<br><br>
Suggestion : ".$frmdata['description']."<br><br> Click here for <a href='http://www.tatanykshipping.com/index.php'>login</a><br><br> Thanks,<br>The TATA NYK Team";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Tata NYK <".$_SESSION['EMAIL_ID'].">\r\n";
$headers .= "Organization: Tata NYK\r\n";
echo '<br>sending mail to = ',$email_id;
if(mail($email_id,$subject,$mail_msg,$headers))
echo '<br>Successs';
else
echo '<br>Fail';
Thanks a lot in advance.
If your PHP application is running on Linux and expecting to send mail from that system, you need a transport. I use sendmail, but there are other open source transports you can use. You may also have to install an email client, but I do not know how PHP interacts with sending mail. My applications act like an email client, and need the email client installed.
You also need to make sure that the email recipient will accept unsolicited port 25 traffic. Because of spam-ware, our firewall won't accept unsolicited port 25 traffic, so I have doctored up sendmail to log into our email server as a legitimate email account.
I ran into a wee issue when using mail(). I wasn't able to send to addresses off the domain I was hosting the form. I understand this is for security reasons but it makes the creation of a 'send to friend' system a little tough.
Here's what I had working (albeit it only sent to my address):
<?php
$senderName = $_POST['name'];
$friendsEmail = $_POST['friendsEmail'];
if ($_POST['formName'] == 'refer') {
$to = $friendsEmail;
$subject = "$senderName has referred you";
$message = "Message goes here";
$headers = "MIME-Version: 1.0\r\n";
$headers = "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: Me <no-reply#test.com>' . "\r\n";
mail($to,$subject,$message,$headers);
}
header("Location: referConfirm.html");
?>
I've talked to my hosting company who setup a mail relay (yay!). Trouble is, I have no idea how to get what I working above through a mail relay. I have the following details:
IP: 000.000.000.000
Domain: domain.company.com
UN: username
PW: password
(Details are dummy.)
Can anyone give me a clue?
Thanks,
#rrfive
mail() uses the smtp/sendmail settings found in php.ini. If you need to send it via another smtp, or one with authentication (like in your example) mail is simply not enough.
There are good mailer libraries out there, just to name a few:
Swift Mailer
Zend_Mail
PHPMailer
They are all capable of sending emails via an authenticated smtp server.