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.
Related
I am trying to use Yahoo SMTP server to send emails from a web site, located on local Windows server and based on Xampp.
As a result, this is what I have in my sendmail settings :
smtp_server=smtp.mail.yahoo.com
smtp_port=465
smtp_ssl=auto
auth_username=box1#yahoo.com
auth_password=pswd1
Then in PHP :
mail ('box1#yahoo.com', 'Static Mail 1', 'Static Message');
mail ('box2#yahoo.com', 'Static Mail 2', 'Static Message');
So, I am trying to send email from one Yahoo account to another but it does not work.
I tried to send emails with GMail SMTP and it works fine but when I try to do this through Yahoo SMTP I always get an error :
From address not verified - see http://help.yahoo.com/l/us/yahoo/mail/original/manage/sendfrom-07.html
As far as I know, this is a common problem when Yahoo does not allow to send emails on behalf of it, but in my case I am sending messages only between Yahoo accounts, what am I doing wrong?
Issue for cross server requests is described here but in some reason I am experiencing it even when I use only Yahoo accounts too.
Seems like the error is pretty self explanatory, add the fourth paramater for the mail function, something like this:
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
php code:
<?php
$to = 'vickee#hotmail.com';
$subject = 'Testing sendmail.exe';
$message = 'Hi, you just received an email using sendmail!';
$headers = 'From: vignesh#gmail.com' . "\r\n" .
'Reply-To: vignesh#gmail.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
?>
I have enabled second step verification in gmail. Is the prob due to that and I get "Email sent" when I run the php code. But there are no mails in the sent or recipient's inbox or junk folder. Are there any alternative methods? If so, please comment link for step by step procedure to send emails using the service.
EDIT:
I've setup the mailing part as instructed in http://arpanthakrar.blogspot.in/2013/06/send-email-from-localhostwamp-server.html
Please do let me know if there are anyother methods or changes to be made in this method.
Let me clearify a bit the "sending" of E-Mail:
$to = 'vickee#hotmail.com';
...
$headers = 'From: vignesh#gmail.com' . "\r\n" .
that means: send an email to "vickee, coming from vignesh"
That does not mean: "Use gmail to send an email to vickee"
Instead, PHP is using the local mailer to transport the mail. The mail is passed by your box, your providers MTA etc. to vickee's inbox at hotmail.
Your gmail account is not involved in to this. So looking in to the "sent" folder of your gmail account doesn't make sense, instead look in to vickees inbox.
Edit:
The "real" sending of the mail is done by the local MTA (Mail Transfer Agent). This is either sendmail, postfix or any other local service.
It's not part of or task of PHP.
PHP is only passing the mail to the configured MTA (usually locally).
Thus: you need to check your e-mail setup first!
I've got a form page on my website where the user has to enter his email ID. As soon as he does that an email should get triggered to him. I've used the mail() function but the email isn't going through. This is on a remote server. Am I missing out on something? Below is the PHP code that I'm using.
<?php
$to = 'xyz#gmail.com';
$subject = 'Demo mail';
$message = 'This is a demo mail. Please reply to make sure the mail communication is okay.';
$headers = 'From: abc#gmail.com' . "\r\n" .
'Reply-To: abc#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed</p>");
}
?>
The output is Email delivery failed!
What is it that I'm supposed to do apart from this? Thank you in advance!
mail() function relies on email configuration of the server the program is running on. You should take a look at your server email configuration, or use a library in order to hook up with an external SMTP service, like Gmail or one of your email servers. I recommend the Swift email library, which is well known, it's thoroughly tested and has a great community behind:
http://swiftmailer.org/
check php.ini config file for SMTP connection or add ini_set("SMTP", "IP_ADDRESS"); in your script.
you can also wrap your script with a error handler to debug the SMTP connection.
websiteI want my website to automatically generate an email to be sent to a customer when they click the submit button.
I have added the following php:
$subject = "Thank You";
$message = "Thank you .........";
$from = "info#mywebsite.com";
$headers = "From:" . $from;
mail($email, $subject, $message, $headers);
The variable $email was defined earlier. Also I have edited my php.ini to include the following:
SMTP = smtp.mywebsite.com
smtp_port = 25
username = info#mywebsite.com
password = password
sendmail_from = info#mywebsites.com
Clearly I have not done enough. What more do I need to do?
This question is duplicate with Sending email with PHP from an SMTP server
PHP mail function has some issue with smtp. (It is not support for smtp user name and password) Use 3rd party mail library like Swift mailer, PHPMailer, etc...
All,
I have the following code:
$to = $friend_email[$x];
$subject = "Subject";
$message = "This is a message";
$from = $your_email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
When the email sends (I'm using Godaddy's hosting service) it says From correctly but then in gmail it says via pxnlhgxxx.prod.xhx3.secureserver.net. Is there anyway to hide the via part or make it say something like website.com? Thanks for the help.
As per the mail() docs, you use the optional 5th parameter for the function and pass in the name of the server you'd like to masquerade as:
mail($to, $subject, $message, $headers, "-f sender#website.com");
If your hosting off godaddy then something like that will happen. You can use your own SMTP server, or use Google free SMTP Server (logging in with your gmail account). Host Gator does the same thing.
You can prevent Google from showing the 'via' notice by DKIM signing your outgoing mail to prove that you genuinely control the domain you're sending e-mail on behalf of.
Its all up to the configuration of the smtp server.