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);
?>
Related
I've written a mail script as;
<?php
$to = 'something#domain.com';
$subject = 'This is subject!';
$body = 'Welcome to our website!';
$headers = 'From: myemail#mydomain.com' . "\r\n" .
'Reply-To: myemail#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$sent = mail($to, $subject, $body, $headers);
if($sent) {
echo "Your mail has been sent to ". $to .".";
} else {
echo "You mail was not sent.";
}
?>
And I could see the echo "Your mail has been sent to someone#somedomain.com" for mail being sent in all of the cases regardless of what email is but the emails are being delivered only to something#gmail.com but never on something#hotmail.com or something#yahoo.com or something#domain.com (hosted on google apps).
I wonder if there is any server configuration missing or the server has been blocked for hotmail/yahoomail or any error there is? Is there any thing you guys can help/suggest me for this?
I've configured my cPanel mail to be recieved at google apps, but I think that doesn't matter as I am trying to send mail, not recieve with this code here.
And yes, I've tried checking in the SPAM/JUNK folders and also waited lots of minutes to see them not being delivered. ;(
Hello Please check sender email sendbox also ,there may be mail in sendbox with some error message. or it may be that on your host the reverse DNS wasn't setup correctly..thanks.
You must authenticate your email with your password before sending, so it won't get blocked in the server. if you use mail class like phpmailer to send mails, following example will help you.
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Username = "yourname#yourdomain"; // SMTP account username
$mail->Password = "yourpassword"; // SMTP account password
Php mailer -- Download phpmailer in this website.
SMTP demo -- Nice tutorial how to use php mailer to send authenticated mails.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP mail using Gmail
code :
<?
//change this to your email.
$to = "bhavesh412#gmail.com";
$from = "bhavesh412#gmail.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
* maaking.com
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa#p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email#maaking.cXom[/email]";
// now lets send the email.
ini_set("SMTP","smtp.gmail.com");
ini_set("smtp_port","465");
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
I am getting below error:
Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\xampp\htdocs\testMail.php on line 31
Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\testMail.php on line 33
Gmail servers use TLS and login/password authentification, you can't use them with PHP's mail() function.
Try using a mail library like Swiftmailer. Here is an example that may work with Gmail: http://swiftmailer.org/wikidocs/v3/connections/smtp
You need to use SMTP authorization for gmail's SMTP server to work which you can't do with mail.
Take a look at PHPMailer they have a good example here.
sometimes an isp provides free smtp service for their clients to some degree. google yourisp & smtp.
I'm trying to send mails from my server by google app.
I am using this php code :-
$to = "username#gmail.com";
$header = "From: username#netvigator.com";
$subject = "testing mail";
$message = "no reply pls";
ini_set("SMTP","smtp.gmail.com");
ini_set("SMTP_PORT", 23);
ini_set("sendmail_from","username#fullpiracy.com");
ini_set("auth_username","username#fullpiracy.com");
ini_set("auth_password","password");
mail($to, $subject, $message, $header);
Thanks in advance !
This was done with send mail open source library.
http://www.sendmail.com/sm/open_source/
I believe Gmail uses SSL (or TLS), so you should adjust your settings accordingly.
The port is usually 465 for ssl connection and 587 for TLS, and address are ssl://smtp.gmail.com and tls://smtp.gmail.com respectively.
Here is a link to a useful SO question that may be helpful.
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.
thanks a lot for helping for previous one.
now another is here.
this is the response when i try to run the code.
<h3>copy of this order has been emailed to you for your records.</h3>
<?php echo $html_body;
//send email
$headers = array();
$headers[]= 'MIME-Versioon: 1.0';
$headers[] = 'Content-type: text/html;charset="iso-8859-1"';
$headers[] = 'Content-Transfer-Encoding: 7bit';
$headers[] = 'From: <priyambikap#gmail.com>';
$headers[] ='Bcc: <priyambika#hotmail.com>';
mail($email,"OrderConformation",$html_head.$html_body,join("\r\n",$headers));
Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for y4yogeshtanwar#gmail.com in C:\xampp\htdocs\flowers\checkout3.php on line 388
bottom line is that i know nothing about how to configure server to be useful for php scripting.i am using xampp for developing this app.
You are using your gmail address as the outgoing address.
That can't work, and if it did, your mails would get caught in any decent spam filter.
You need to specify a valid sender address on the domain the PHP script runs on.