PHP mail() returns true but doesn't work
Posted on
16th Feb 2014 07:03 pm by
admin
First off I apologize if this is a newbie question, and I generally don't like asking questions that have already been asked 1,000,000 times, but I've searched far and wide and cannot find a solution to my problem.
Basically I run an experimental server on my home network. I use LAMP (Ubuntu Server, Apache2.2, MySQL5, PHP5).
I simply want to take the data from an HTML form and submit it as an e-mail. I tried using the mail() function like this:
Code: $email = $_POST['email'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$sentmail = mail("example@gmail.com",$subject,$message,"FROM: ".$email."rn");
if($sentmail) {
echo 'Your message has been sent!';
} else {
echo 'Cannot send message.';
}
After some googling, I found one solution that said to add this line:
Code: ini_set("sendmail_from", "example@gmail.com");but it made no difference.
I finally decided to try a different approach using SMTP:
Code: require_once "Mail.php";
$from = "Form Data <".$_POST['email'].">";
$to = "My Name <example@gmail.com>";
$subject = $_POST['subject'];
$body = $_POST['message'];
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "foo@gmail.com";
$password = "bar";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
Still not working!
This is quite frustrating. It always returns a value of "true" but never actually sends the messages!
Maybe it would help if I had a better understanding of what the mail() function actually does. Where does the message go when handled by mail()? Mustn't it go through a mail server at some point? Port 25 is iffy on my setup, so that could be the issue with mail().
When using the PEAR method though, I specifically indicate port 465, so that can't be the issue.
What am I missing here?
314
21
Other php-forum
limitations on array_unique()
Does any one know what/how imitations are applied to array_unique? I have an issue where no matter h
problem in pagination when processing with selectbox form
Hi,
I have a search form, with select boxes, if am selecting the value from the form, it work
Session
I am having a little trouble with a session. Not sure if it is my browser or what. I know I do not
TimeZoneOffset
Hello,
Please i need your help. I have a system that users can use to punch in and out. This
Port scanner problem
Hai
recently i developed one app through which u can check the opened and closed ports under an
sql problems
I am having a small problem with my sql statement. it is inserting into 4 of the fields.
fie
difference between datetimes
($row['totime']-$row['fromtime'])/60
this is giving me 0
example of totime and fromtim
Help with Contact Form
I have this Form on an html page and the associated code on page.php (below).
I keep getting the
Remove letter from numeric textbox
I have a textbox that will search the employee database by entering in the employee ID and it will r
How do I get the row number from from an sql table query
Hi all
I have a table that I query and it returns a number of rows.
mysql_num_rows($query)