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.
Related
I am using php mail function its working fine for gmail but when i send it to domain email it show me successful message but not receive on my domain email side where i am wrong. my code is below
<?php
$to=$_POST['to'];
$from=abc#gmail.com;
$name="abc";
$subject=$_POST['subject'];
$message=$_POST['message'];
$headers = 'From:'. $name ."\r\n" .
'Reply-To:'. $from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers,"-f".$from);
echo "Message sent! <a href='mail.php'>Click here</a> to send another email.";
?>
my domain email is contact#automailer.netai.net how can i fix this issue,
There are two completely different processes involved:
Queueing the mail to your local MTA (This is what PHP's mail() does)
This MTA delivering (with possible hops in between) to the final MTA, which delivers into the users mailbox
Obviously PHP only knows about the first step and may be right to consider it successfully done even if something else later goes wrong - e.g. the receiver domain simply not accepting your mail (which sadly is the new normal).
most likely automailer.netai.net is blacklisted and that's why you aren't getting emails.
try using phpMailer library which is free or popular smtp api that offer free trial as long yo don't pass 10,000 emails per month from
sendgrid.com,
maildrill, etc
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!
can someone please help me figure out why this isn't sending? I'm new to PHP.
It's for a contact form on my website. I'm sending from my server (not localhost) and receiving the console message "Mail not sent"
<?php
include 'ChromePhp.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$to = 'me#myemail.com';
$subject = 'Email from Me';
$message = $_POST['email'];
if(mail($to, $subject, $message)){
ChromePHP::log( 'Mail Sent');
}else{
ChromePHP::log( 'Mail Not Sent');
}
}
?>
I realise this question has been asked before, but I can't find an answer that works. Thanks in advance!
You should include header to mail() function, example
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
then insert $headers parameter to mail() function:
mail($to, $subject, $message, $headers);
Without an error message, I can only guess. You probably need to set the SMPT server in your php.ini. You can do that at runtime using ini_set('SMTP', 'your_server_here').
More about the mail configuration here: http://php.net/manual/en/mail.configuration.php
If you don't have one, you can check if your ISP has an open server. ISPs sometimes have open SMTP servers (outgoing servers) and you can find them by looking for instructions on how to set up your mail program (Outlook).
Be careful though, and don't use this for anything but light testing. I can imagine they won't like a lot of spam going through their server.
EDIT: Also, read up on the headers required. I see you're missing a From header, which should result in a warning. See here: http://php.net/manual/en/function.mail.php
When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.
You should check your mail services, because above PHP code quite true.
You can ask to your hosting provider to activate mail services because some hosting provider does not allow to use mail in default.
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.
I have an email form that isn't sending out an email to the recipient or a copy to the client. The form can be found at www.kelcos.co.uk/contact and the files associated with this are:
/index.php
/jquery.js
/sendemail.php
/submitform.php
/thanks.php
/verify.php
I have used this form on other websites http://www.bowlesgreen.co.uk/contact/ and http://www.arbortectreecare.co.uk/contact/ and it works fine - the only difference is that these other sites use my usual hosting provider and for the one that won't send I'm working through the clients hosting provider, which I can only presume is what is causing the problem.
I have contacted the hosting and so far we have eliminated a few things such as:
'The limitation to our systems is that the emails sent using scripts will be blocked if they are not going to or coming from an email address setup on the web hosting account. - so I am now sending the form to an a kelcos.co.uk address, but still no joy.
PHP/ASP was originally disabled, but now has been activated
the mail() script is enabled
I would really appreciated any advise any of you could offer.
Thanks
No, http://www.bowlesgreen.co.uk/contact/ doesn't work fine as you said. Firebug reports: POST http://www.bowlesgreen.co.uk/projects/wp/wp-content/themes/bowlesgreen/contactform/sendemail.php 404 Not Found
Your forms are submitting to the wrong URL.
Is Qmail available on the server? Are you setting the headers properly?
Try something like the following:
putenv ("QMAILUSER=myuser");
putenv ("QMAILNAME=My Name");
putenv ("QMAILHOST=mydomain.com");
$headers = 'From: My Name <myname#mydomain.com>' . "\r\n" .
'Reply-To: My Name <myname#mydomain.com>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail_to = 'myemail#myemail.com';
$subject = "Testing email";
$body = "This mail is a test";
mail($mail_to, $subject, $body, $headers);
And see if you receive an email!
try these
http://forum.codecall.net/php-forum/28696-php-contact-form-isnt-sending-out-email.html
http://www.astahost.com/info.php/Php-Send-Email-Problem_t2259.html