Jump to content

Mail() function


samona

Recommended Posts

Hi,

I'm trying to send email using PHP and a remote Windows smtp server.  I changed my php.ini file to point to the ip address of the server and set the From settings.  The next thing I did was:

 

1. Upload the script

 

<?php
$to = "samona@gmail.com";
$subject = "Hi!";
$body = "Hi,\n\nHello World!";
if (mail($to, $subject, $body)) {
  echo("<p>Message successfully sent!</p>");
} else {
  echo("<p>Message delivery failed...</p>");
}
?>

 

2.  I uploaded the script to my server.

3.  I opened the page where the script is located and I get an error saying Message delivery failed...

 

What am I doing wrong?  Thanks in advance.

Link to comment
Share on other sites

Add the following two lines after your first opening <?php tag to get php to help you find why the mail() function call failed -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

Unless your IP address is "trusted" by the remote mail server, it will typically require that you authenticate against an email account on that server using SMTP Authentication (the same as if you were using a email client like Outlook.) The mail() function does not support SMTP Authentication. You would need to use something like the phpmailer class, which opens a socket connection with the mail server and exchanges STMP commands.

Link to comment
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.