0

I have a mail function in my PHP file . When I excecute the file it doesn't give me any error messages but the email is not sent either. I have installed and started the Mercury Mail.

Here is my code:

$result = mysql_query("select email from user
                        where username='$username'");
$email = mysql_result($result, 0, "email");
$from = "another_emailgmail.com";
$mesg = "Your password have been changed";



if (mail($email, "Login information", $mesg, $from))
    return true;

I have looking in another similar post but it seems they have not installed Mercury Mail and they dont't have the same problem.

Pirlo
  • 99
  • 1
  • 1
  • 9

3 Answers3

0

This code works out-the-box (change your e-mail address!). mail() function return a bool value, then if it returns TRUE you have to check your system log and system e-mail spool looking for routing errors or something similar.

<?php
if(mail('some_email@gmail.com','E-mail subject',"E-mail body\r\n")){
  echo 'Works'."\n";
}else{
  echo 'Failed'."\n";
}
  • It gives me "Works" but I still don't recieve any message. – Pirlo Aug 21 '14 at 09:12
  • Yes, it's correct. Your problem is NOT on PHP side, but deep on your SMTP software. PHP just delegate sending to your SMTP, aka PHP do NOT send any e-mail directly. You have to look your SMTP logs to looking for errors. – Andrej Pandovich Aug 21 '14 at 09:18
0
mail($mailto, $subject,stripslashes($message), $headers);

Headers Can be set as below

        $headers .= 'From:from@gmail.com' . "\r\n";
arunrc
  • 628
  • 2
  • 14
  • 26
0

Try this.changes the fields according to your needs.just change the data according to your need

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "To: $mydata->name <$mydata->email>" . "\r\n";
$headers .= "From: demo.com <contact@demo.com>" . "\r\n";

mail($mydata->email, $subject, $message, $headers);
Aksh
  • 654
  • 6
  • 13