Jump to content

Help with mail()


RobertSubnet

Recommended Posts

Greetings all. I am having a problem using mail() and was hoping some kind soul could give me some feedback as to what I am doing wrong.

 

When executing the script, IE just hangs. No error messages, the first part of the script doesn't even run. IE just times out with a blank page.

 

None of my other scripts do this.

 

I am using a mail server on my local network which I have confirmed works, using Outlook Express to send test messages to Yahoo.

 

SMTP port 80

PHP v.5.2.3

INI settings:

sendmail_from [email protected]

sendmail_path no value

SMTP localhost (IIS and the mail server are on the same machine 192.168.1.204)

smtp_port 80

 

The code I am using:

 

<?php

$to = "[email protected]";

$subject = "Hi!";

$body = "Hi,\n\nHow are you?";

echo "this script will attempt to send an e-mail to $to";

 

if (mail($to, $subject, $body)) {

  echo"Message successfully sent!";

} else {

  echo"Message delivery failed...";

}

?>

 

Thank you for taking the time to look this over.

~Robert

 

 

Link to comment
https://forums.phpfreaks.com/topic/71927-help-with-mail/
Share on other sites

Well I finally got it figured out. It seems that not having the From header is what caused the problem. Below is the code that works:

 

<?php

$to = '[email protected]';

$subject = 'Hello!';

$message = 'Hello from your friendly PHP script';

$headers = 'From: [email protected]';

 

echo "This sends an email to $to";

echo '<br>';

 

if(mail($to,$subject,$message,$headers)) {

  echo "Message successfully sent!";

} else {

  echo "Message delivery failed...";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/71927-help-with-mail/#findComment-363159
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.