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
Related
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.
I have a PHP customer input form which sends out SMTP mail to the company hosting the form. For some reason the emails are not reaching the recipient's email. If I substitute in any other email address not on the domain it works out fine. I can also list multiple addresses on the To: line and the others will get the email but not the desired info# email address. I cannot change the sending domain since my web hosting won't send mail when they are mismatched. I thought that it might have to do with the sending email address and receiving being the same so I changed the From: address to "onlineform#" instead of "info#" but that made no difference.
I'm perplexed as to what's happening here. I can send email directly from any other account to the "info#" email address and that works fine. I've asked them to check their client and server junk mail folders and they are both clean. Any ideas on what's going on or how to further diagnose the issue? I've simplified the code down to the relevant parts below and the snippet code does the same thing.
<?php
$email_to = "info#domain.tld";
$email_subject = "Subject line here";
$email_message = "Email body here.";
$headers = 'From: onlineform#domain.tld'."\r\n".
'Reply-To: noreply#domain.tld'."\r\n" .
'X-Mailer: PHP/' . phpversion();
#mail($email_to, $email_subject, $email_message, $headers);
?>
It could have something to do to the server's mail policy. You may be telling the server that the message is being sent from whatever#domain.tld, but you are not proving it.
Have you tried to send using SMTP authentication? Not sure this is actually the real problem, but it worth testing.
Also, I recommend you to always use mail solutions instead of using the plain php mail() function. I've used PHP Mailer for a long time and not only it works fine, it always eased the boring process of sending e-mails through php.
When I send mail via PHP's mail() it sends the wrong header information...
$to = 'mypersonal#gmail.com';
$subject = 'the subject';
$message = 'hello, hi :)';
$headers = 'From: Support <support#site.com>' . "\r\n" .
'Reply-To: From: support#site.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
in my gmail it shows
Support via mydedicatedserver.dediprovider.com
How can I configure PHP mail() to send my domain name?
mail() is already sending your domain name.
Gmail sometimes displays that message when Google is not familiar with your server and the hostname of your server does not match the domain name you're sending e-mail from. It's an anti-spam/anti-phishing measure.
Add proper SPF records to your domain. If the server is under your control, try changing its hostname to something that includes your domain name, like server1.site.com. Follow all other advice listed in the link below. Even then, there is no guarantee that Gmail will drop the message right away. In my experience, that message goes away after a while when Google becomes familiar with e-mails from your server and decides that none of them are spam. But Google seems reluctant to disclose exactly what is required, probably because they don't want spammers to get too clever.
See: https://support.google.com/mail/bin/answer.py?hl=en&answer=1311182
Also, the Reply-To: From: header is wrong.
http://www.raymondselda.com/php-contact-form-with-jquery-validation/
I'm trying a few different contact forms including the one above.
I have it running on this page: http://themeforward.com/demo2/features/contact-form/
The problem is this form does not successfully send e-mails to the address in the code (finished code can be found here: http://www.raymondselda.com/php-contact-form-with-jquery-validation/ )
Does anybody know what the problem may be?
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'youremail#email.com'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
Many reasons:
Mail isn't configured properly on your server. mail() will return a boolean FALSE if it can't hand off the email to an SMTP server. You're not checking for that condition
The SMTP server isn't configured properly to allow you to send through it
The receiver server has your sending server blacklisted
The email is treated as spam and is getting trashed
First place to start looking is mail()'s return value. Then go look at your SMTP server's log to see what happens to the email (if) once PHP handed it over. The SMTP server's log will also say if the receiving server bounced/refused it.
If it's getting silently thrown in a spam folder on the receiver server, there'll be NO evidence of this on your end, and you'll have to investigate further on the receiving end.
Email is a complicated business with many many invididual steps where each one has to work right. Any glitches anywhere along the line and the email is probably gone. You have to investigate what happens at EACH of these stages to figure out why something isn't being delivered.
I have the following code which works on some servers and does not work on others:
$Name = "myname"; //senders name
$email_sender = "myemail.dia#gmail.com"; //senders e-mail adress
$recipient = $email; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email_sender . ">\r\n";
$status = mail($recipient, $subject, $mail_body, $header);
print('ENVOI '. $status);
The $status variable is true but I don't see any email.
$status being true doesn't mean the mail was RECEIVED by your recipient. It just means the mail function successfully delivered the mail to the LOCAL delivery agent. After that it's out of PHP's hands.
The process looks something like this:
PHP script calls mail()
mail() delivers message to the local mail server (sendmail, postfix, exim, etc..)
mail(), having successfully completed 'delivery' of the email, returns TRUE
local mail server connect's to recipient's mail server, delivers mail
recipient's mail server does whatever it has to to get the email into the recipient's inbox.
Since mail() is returning true, that means that at least your sending code is correct enough to not cause things to blow up at that stage. That leaves delivery problems between your and the recipients' mail servers:
a) Perhaps the recipient is using greylisting (in which case the mail SHOULD eventually show up). Maybe your server gives up before the greylist timeout period expires, so the retry attempt(s) is never made.
b) your mail server is blacklisted. Your server, and/or some other potential spam source is in the same netblock have been added to one or more anti-spam RBL lists the recipient subscribes to.
c) Perhaps the remote server is very prickly about header correctness and your server's a bit too relaxed about one or more headers.
At least these problems SHOULD be visible in your own mail server's maillog (generally /var/log/maillog on most Unix-ish systems). Try sending a test mail while watching the log to see how the message procedes through the system. Also check the server's outgoing mail queue (mailq command, usually). Maybe the missing messages are stuck in there.
And then there's the bigger problems:
d) the remote mail server is accepting the message, but silently tossing it because it's flagged as spam or as infected. This you can't detect from your own mail logs, as this is done purely on the recipient end. All you'll see is the "250 OK" success message.
For this you'll need the recipient's help in diagnosing the problem.
This may or may not be related but you have a pretty simple header, I would replace your header variable with something like what's below and see if that changes anything for you.
$headers = 'From: ' .$email_sender. "\r\n" .
'Reply-To: ' .$email_sender. "\r\n" .
'X-Mailer: PHP/' . phpversion();
Make sure you smtp setting are correct on the servers in question.