www.webdeveloper.com
Results 1 to 6 of 6

Thread: PHP Mail function not working - deployed in Windows server

  1. #1
    Join Date
    Apr 2014
    Posts
    2

    Question PHP Mail function not working - deployed in Windows server

    I am new to PHP, I have a website done in HTML and PHP. There is a form that sends mail. I have set up the Pear Mail package as per http://email.about.com/od/emailprogr...entication.htm

    The following is my PHP file to send mail.
    PHP Code:
    <?php
    // multiple recipients
    $to  'test1@test.com' ', '// note the comma
    $to .= 'test2@test.com';

    // subject
    $subject 'Birthday Reminders for August';

    // message
    $message '
    <html>
    <head>
      <title>Birthday Reminders for August</title>
    </head>
    <body>
      <p>Here are the birthdays upcoming in August!</p>
      <table>
        <tr>
          <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
        </tr>
        <tr>
          <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
        </tr>
        <tr>
          <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
        </tr>
      </table>
    </body>
    </html>
    '
    ;

    // To send HTML mail, the Content-type header must be set
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

    // Additional headers
    $headers .= 'To: Mary <test1@test.com>, Kelly <kelly@example.com>' "\r\n";
    $headers .= 'From: Birthday Reminder <no-reply@test.com>' "\r\n";
    $headers .= 'Cc: [email]test1@test.com[/email]' "\r\n";
    $headers .= 'Bcc: [email]test1@test.com[/email]' "\r\n";


    // Mail it
    try
    {
    if(
    mail($to$subject$message$headers))
    {
        echo(
    "<p>Email successfully sent!</p>");
        } else{
        echo(
    "<p> Email delivery failed </p>");
        }
    }
    catch(
    Exception $e){
    echo 
    'Caught Exception'$e->getMessage(), "\n";
    }
    ?>
    The mail function is failing. I get the response as "Email Delivery Failed" I have been searching on google for a day now, but havent found any solution. Thanks in advance.
    Last edited by NogDog; 04-14-2014 at 03:57 PM. Reason: added [php] tags around code

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    Welcome to the forums. Note that I added [php]...[/php] tags around your code so that it's easier for us to read. Please use applicable bbcode tags in your future posts. Now give me a minute or two to actually read your question and code...
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,408
    a. You do not appear to actually be using PEAR::Mail, in case that is important to you. (You are simply using the built-in PHP mail() function.)

    b. There is no reason to add a "To:" mail header to your $headers, since that is handled by the first parameter passed to mail(). I don't know if including it in your additional headers might be a problem or not.

    c. Many mail servers will fail if the email address used for the "From:" header is not a valid email address on that server, so double-check that. (If you want replies to go to a different address, use the "Reply-To:" header for that.)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    Quote Originally Posted by NogDog View Post
    There is no reason to add a "To:" mail header to your $headers, since that is handled by the first parameter passed to mail(). I don't know if including it in your additional headers might be a problem or not.
    if i remember right, you can use one or the other, but not both. imo using the "To" in the headers parameter makes the most sense, esp. if you are bulk mailing.
    PHP Code:
    <?php
    if(!mail(NULL$subject$message$additional_headers))
    {
        
    // mail() failed to send...
    }
    ?>

  5. #5
    Try to use the PHP mail function like this:
    <?php
    $to = 'hello@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: abc@example.com' . "\r\n" .
    'Reply-To: abc@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
    ?>

  6. #6
    Join Date
    Apr 2014
    Posts
    2

    Tried this but, I am still not getting the mail

    Quote Originally Posted by robertsullivan View Post
    Try to use the PHP mail function like this:
    <?php
    $to = 'hello@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: abc@example.com' . "\r\n" .
    'Reply-To: abc@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

    mail($to, $subject, $message, $headers);
    ?>
    Tried the above code but its not working. Mail function is returning false. Do I need to set up some configuration in IIS of the Windows Server?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles