please help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chunk1978
    New Member
    • Jan 2007
    • 224

    please help

    here's a mail() example i found on a site, i put my own address in the $to section... but all i get is "Mail Failed" message... what am i doing wrong?

    Code:
    <?php
    //define the receiver of the email
    $to = 'chunk1978@gmail.com';
    //define the subject of the email
    $subject = 'Test HTML email'; 
    //create a boundary string. It must be unique 
    //so we use the MD5 algorithm to generate a random hash
    $random_hash = md5(date('r', time())); 
    //define the headers we want passed. Note that they are separated with \n
    $headers = "From: webmaster@example.com\nReply-To: webmaster@example.com";
    //add boundary string and mime type specification
    $headers .= "\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
    //define the body of the message.
    ob_start(); //Turn on output buffering
    ?>
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    Hello World!!! 
    This is simple text email message. 
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    <h2>Hello World!</h2>
    <p>This is something with <b>HTML</b> formatting.</p> 
    
    --PHP-alt-<?php echo $random_hash; ?>--
    <?
    //copy current buffer contents into $message variable and delete current output buffer
    $message = ob_get_clean();
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Most likely, you do not have an SMTP server correctly configured on your server. Use PHP info to check that all of the SMTP server information is correct in your php.ini file.

    Originally posted by chunk1978
    here's a mail() example i found on a site, i put my own address in the $to section... but all i get is "Mail Failed" message... what am i doing wrong?

    Code:
    <?php
    //define the receiver of the email
    $to = 'chunk1978@gmail.com';
    //define the subject of the email
    $subject = 'Test HTML email'; 
    //create a boundary string. It must be unique 
    //so we use the MD5 algorithm to generate a random hash
    $random_hash = md5(date('r', time())); 
    //define the headers we want passed. Note that they are separated with \n
    $headers = "From: webmaster@example.com\nReply-To: webmaster@example.com";
    //add boundary string and mime type specification
    $headers .= "\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
    //define the body of the message.
    ob_start(); //Turn on output buffering
    ?>
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/plain; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    Hello World!!! 
    This is simple text email message. 
    
    --PHP-alt-<?php echo $random_hash; ?>  
    Content-Type: text/html; charset="iso-8859-1" 
    Content-Transfer-Encoding: 7bit
    
    <h2>Hello World!</h2>
    <p>This is something with <b>HTML</b> formatting.</p> 
    
    --PHP-alt-<?php echo $random_hash; ?>--
    <?
    //copy current buffer contents into $message variable and delete current output buffer
    $message = ob_get_clean();
    //send the email
    $mail_sent = @mail( $to, $subject, $message, $headers );
    //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
    echo $mail_sent ? "Mail sent" : "Mail failed";
    ?>

    Comment

    • chunk1978
      New Member
      • Jan 2007
      • 224

      #3
      Originally posted by Motoma
      Most likely, you do not have an SMTP server correctly configured on your server. Use PHP info to check that all of the SMTP server information is correct in your php.ini file.
      hi motoma, thanks for the reply... i'll be subscribing to a community based server, so i won't have access to the php.ini file... however, they told me that my custom php scripts will work because they have php4.4.3 and sendmail installed on their server... smtp config in the .ini file is either set up for windows or unix right? so at least one of them should work when it comes time to test the script... i'm assuming based on what you suggested, that this script looks fine and should work... i guess it depends on what carriage returs i use? "\n" for unix and "\r\n" for windows?

      Comment

      Working...