1

Possible Duplicate:
php mail function

I am doing this website where I send emails to users when they for example forget their password or similar, but for some reason I can not send emails with the following function:

$email = 'somemail@mail.com';
$subject = 'subject';
$message = 'message blablablablabla';


mail($email, $subject, $message);

Am I doing something wrong or missing something in the code, or is it the hosting company's fault? (I make my website on x10hosting.com). I checked in the manual about mail() but it didn't help me. Thanks in advance.

Update

Thanks for the help guys, but it turned out to be a problem on the web hosting company I'm on. Everything's working fine now.

Community
  • 1
  • 1
DannyCruzeira
  • 564
  • 1
  • 6
  • 19

3 Answers3

1

try to use with headersenter code here

     $headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n";
$headers .= "From: <".$frommail.">\r\n";
$headers .= "Reply-To: ".$frommail."\r\n";
$mail_sent=mail($tomail,  $msg, $headers);`enter code here`
heart_hacker
  • 115
  • 2
1

I would guess either there is no sendmail_from value set in php.ini or your host does not support email or has not set it up correctly.

Try setting a from header, and if that doesn't work, contact your host:

mail($email, $subject, $message,'From: you@example.com');

Mitch Satchwell
  • 4,770
  • 2
  • 24
  • 31
1

is this on local host? or is it on a webserver

Also remember that mail($to, $subject, $contents) returns a boolean,

  if(mail($to, $subject, $body){
       echo "Message has been sent";
  }
  else{
       echo "Error has occurred"
  }
DWolf
  • 703
  • 1
  • 7
  • 20
  • It says: "message has been sent", but I still don't get anything neither on Gmail nor on hotmail. But thanks for the help. – DannyCruzeira Nov 06 '12 at 15:12
  • I recently have worked on this, and i did notice a delay.. And if its a gmail account it shows as Unprivileged user.. Have you checked your spam folder? maybe it redirected it there. – DWolf Nov 06 '12 at 15:19
  • Thanks, I will check the spam folder. BTW, how long was the delay for you? – DannyCruzeira Nov 06 '12 at 15:59
  • was between 1-10 minutes, sometimes it was instant. just depended on my connection that day since I was running it locally – DWolf Nov 06 '12 at 16:16