PHP sendmail not sending - php

I have a form that submits to PHP self. This script runs and says it is successful, but I do not receive an email.
if(isset($_POST['name']) and isset($_POST['email']) and isset($_POST['phone']))
{
//setup variables from input
$EMAIL = "anem#il.com";
$inEmail = $_POST['email'];
$subject = "Enquiry from ".$POST['name'];
$name = $_POST['name'];
//setup message
$message = "Enquiry from: ".$name."\nEmail: ".$inEmail."\nPhone: ".$phone."\n\nDeparture Date: ".$departureDate."\n\nreturnDate: ".$returnDate;
$message = wordwrap($message, 70);
//email enquiry details to site owner
if (mail($EMAIL, $subject, $message))
{
echo "Enquiry sent!";
} else
{
echo "fail!";
}
?>
The "Enquiry sent" message does appear.
I have postfix installed and I have also tried with sendmail installed. I have scanned local host using nmap and the smtp port is open.
Can anyone see any reason that the mail does not sent.

Check your mail log (usually /var/log/maillog). It would show the message arriving from PHP, and any delivery attempts/rejection notices from the MX of the receiver.

There a lot of possible reason that could explain why your email is sent and not received. Beside just setting up your SMTP server there are other things you need to do to make sure your email isn't just dropped before it reaches his destination.
You should take a look at this article that explains, what you should check :
http://www.codinghorror.com/blog/2010/04/so-youd-like-to-send-some-email-through-code.html
In summary you need to :
Make sure the computer sending the email has a Reverse PTR record
Configure DomainKeys Identified Mail in your DNS and code
Set up a SenderID record in your DNS

Assuming that sendmail is working on your system, and that PHP is configured to use it correctly, try adding -f in the additional parameters, like this...
mail($EMAIL, $subject, $message, '-fYOURVALIDEMAILADDRESS#something.com'
This sets the envelope with a proper from address. See more on the PHP site: http://www.php.net/manual/en/function.mail.php#92528

Related

how to send email in server using core php?

I have written a email send php code and uploaded onto server. It is working and email is being send to the inbox. But when i uploaded the same code onto another server, it is not working, mail is not being send but the message "your message has been send successfully" is being displayed. why is it like that ? Can anyone tell ?
There are a lot of shared webhosting providers who have disabled PHP's mail() function.
WHat you could do is switch to, for example: PHPMailer
Without seeing you code i'ts not possible to tell you why it isn't working.
You say your getting the message "your message has been send successfully" but that isn't the response from the send() command - that should be a boolean - so check that your code is reading that correctly and reporiting the correct result.
If the send() is returning true then it means your message has left the server but doesn't mean it's arrived at it's destination. Most likely the recipients server is blocking your new server for some reason.
My suggestion is to use an external SMTP server to send the mail through so it's consistent across where ever your app is hosted. Amazon SES is very good, cheap and allows you to easily monitor bounces too.
This is my code for phpgmailer. This is showing the above error.
<?php
$name = $_POST['fname'];
$telephone = $_POST['phone'];
$mobile = $_POST['mobile'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$msg = $_POST['message'];
require_once("phpgmailer/class.phpgmailer.php");
$mail=new PHPGMailer();
$mail->Username="cd4xltech";
$mail->Password="dfddfdfddf";
$mail->From="cd4xltech#gmail.com";
$mail->FromName=$name;
$mail->Subject="Feedback:".$subject;
$mail->AddAddress("annan#gmail.com");
$mail->Body=$message."From: $name";
if(!$mail->Send())
{
echo "Error".$mail->ErrorInfo;
}
else
{
echo "Mail Sent";
}
?>

PHP mail function is not working for Webform

Below is the Webform PHP code I used for e-mail function. After I click the SUBMIT button in the form, I am successfully getting redirected to the thankyou.html page but I don't get any e-mail to my e-mail account. Kind help is deeply appreciated.
PHP Code:
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
mail('myemail#email.com', 'Subject Line', $emailbody);
header('location: thankyou.html');
} else {
header('location: index.html');
}
?>
You may be missing the "From" field in the $additional_headers argument. Try
$headers = 'From: myemail#email.com';
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
It might be a problem with your host.
I think due to the email spams that #email.com got from your host it may be now in the blacklist.
This means you have to contact your host about this problem and tell them to talk with #email.com to remove your host from the blacklist.
I had this problem a while ago on 000webhost.com and they told me i can't send emails to an yahoo.com account because yahoo.com added the 000webhost.com on the blacklist because users spammed the Yahoo servers.
It's likely that your server, or one along the route, is refusing to deliver the mail because it has no From: address. You can add one using the headers parameter for mail():
<?php
if(isset($_POST['submit'])) {
$emailbody = 'Name: '.$_POST['name']."\n"
.'E-mail: '.$_POST['email']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Address: '.$_POST['addr']."\n"
.'City: '.$_POST['city']."\n"
.'State: '.$_POST['state']."\n"
.'Enquiry: '.$_POST['msg'];
// Add extra headers here
$headers = "From:address#examle.com"
mail('myemail#email.com', 'Subject Line', $emailbody, $headers);
header('location: index.html');
} else {
header('location: about-us.html');
}
You should check any user-suplied input to ensure it doesn't try to subvert your mail function by adding headers of its own. Check for text like To:, Cc: or Bcc:.
Most ISPs will refuse to deliver email unless it comes from a domain registered with them. Sometimes the from address must exist on the server generating the mail.
Note that there are other reasons why mail might not be delivered: bad addressing and spam filters to name but two.
I found the answer. I just changed $emailbody into $message and it is working fine now. I am not sure that using $emailbody instead of $message was the issue but it is working fine now.
Thank you all.
First check your hosting server is that providing mail functionality for this you just write
echo phpinfo();
you need to check the mail function enable or not

PHP mail script does not send mail

I have this mail script on my page: mail('myadress#server.com', 'New client added by user', 'test message');
but I do not receive anything! (of course I added my real adress). I tried it with 2 different adresses, looked in my spam folder, etc... just nothing. but the script executes just fine.
Is there any log I can view or invoke to see exactly what happened?
thank you for your help!
<?php
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
try this it will going to work for u ....
1) Check the return value from the mail() call:
$status = mail(...);
if (!$status) {
die("Mail failed");
}
If this fails, then PHP cannot even get the mail out the front door, and you'll have to figure out why - e.g. are you on a Windows box and haven't configured the mail options in php.ini?
2) Check your mail server's logs. Most Unix/Linux systems have a local mail server (the MTA) which will accept the mail from PHP. If it's misconfigured or having trouble, it may still accept the mail from PHP but then leave the mail to rot in a queue.
Perhaps your server's been placed on spam blackhole lists and it simply cannot deliver mail anywhere, which means you've probably got all of your test mails stuck in an outgoing queue that can't go anywhere.
Had to add the header "from" and use an email adress created on the server.

PHP: cannot send sms, but can send regular old email

I am trying to send text messages to my phone from my server using php. I recently configured the server to send email, which it does (verified). It, however, goes into my spam box. When I try to send a message via sms I do not receive anything.
This is the script I am using:
$to = "myemailaddress#gmail.com";
$subject = "testing";
$body = "";
$headers = 'From: testemailaddress#gmail.com';
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
The address that I am using for sms is myphonenumber#txt.att.net in the 'To' field.
I am going to go out on a limb here and say this is a authentication issue, maybe.
Is there anything I need to configure further? (i.e. php.ini)
Most email providers/servers today rely heavily on spam filtering / dnsbl. Your webserver is not a know mail server, and you probably did not set up SPF or anything.
An approach to avoid all those issues would be to utilize a Google Mail address (or any other providers). And instead of the PHP mail function use something more complex like Swiftmailer, which generates Mail headers that are less commonly autoclassified as spam.
See also: Using php's swiftmailer with gmail

Using PHP mail( )

I have a php mail script which works perfectly on a one host. However, when I attempt to use the same script on a network solutions host, the function returns true but no email ever sends.
//get mail function data
$case = $_POST['case'];
$to = addslashes(strip_tags($_POST['to']));
$message = addslashes(strip_tags($_POST['message']));
$subject = addslashes(strip_tags($_POST['subject']));
$message = addslashes(strip_tags($_POST['message']));
$from = "confirmation#website.co";
$headers = "From: $from\r\n";
//send email
if (mail($to,$subject,$message,$headers)){
//formatting for error message
$emailSent = "block";
$emailFailed = "none";
}
else //if the email fails to send
{
$emailSent = "none";
$emailFailed = "block";
}
?>
Does anyone know if different hosts require specific info in mail script?
This is a question for Network Solutions customer support. Sending mail from shared hosting servers is usually well locked down -- if they allow it at all, it's throttled. Also, calling mail just means the message was successfully passed to sendmail, not that the mail ever left the server. It could be sitting in a queue to be sent, it could have bounced for a million reasons beyond your control, etc.
Some hosts have this issue. On mine (Mosso), I had to adjust the last parameter (from) like so:
mail($to, $subject, $message, $headers, "-f".$from)
May not be the solution for NetSol but worth a try. I know some hosts disable the script and require using the smtp class to send mail.
This is assuming, of course, everything is correct with your DNS and MX records. If you're trying to send from an account that is different than the domain being sent from, some providers will automatically block that.
It maybe that they have not enabled php mail, but ask the host for specifics.
Looking at your code it is not cleaning the input sufficiently. take a look at the is_forbidden function here:
http://thedemosite.co.uk/phpformmailer/source_code_php_form_mailer_more_secure_than_cgi_form_mailers.php

Categories