Jump to content

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 robert@kaydoo.com

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 = "robert@yahoo.com";

$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 = 'dude@yahoo.com';

$subject = 'Hello!';

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

$headers = 'From: robert@home.com';

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.