problem in mail function parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hamsika
    New Member
    • Mar 2008
    • 1

    problem in mail function parameters

    Hi ,

    when i run the below code i all the html tags in the message field displayed as html tags(like <html>). plz tell that what's the problem i made .

    Code:
    code :[php] 
    
     $to ="$_POST[email_addr]";
    $subject = "Site Registration Confirmation";
    $message = '<html>
    <head>
    <title>Site Registration Confirmation</title>
    </head>
    
    <body style=font-family:verdana, arial; font-size: .8em;>
    <a title=Confirm Comment
     href=http://www.website.com/confirm.php?c='.$confirmationCode.'>http://www.website.com/confirm.php?c='.$confirmationCode.'</a>
    </body>
    </html>';
    $headers = "MIME-Version: 1.0\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\n";
    $headers .= "X-Priority: 3\n";
    $headers .= "X-MSMail-Priority: Normal\n";
    $headers .= "X-Mailer: php\n"
    $from = "me@example.com";
    $headers = "From: $from";
    
    mail($to,$subject,$message,$headers);
    [/php]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    That code is awfully laid out..

    I stopped sifting through it at about halfway.

    In order to help us help you, you need to: have the code laid out in a readable fasion, USE THE CORECT CODE TAGS (code=php), and also be descriptive as possible in your question.

    Please take into consideration these, and then ask the question again.

    Regards.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      This code is absolutely unreadable and its logic cannot be followed. I think each member in this forum will think the same.

      I presume that you copied this code from a site or an editor that does not have newlines, so all it concatenated.

      Come back with the reformatted code and put it between [php] tags!

      moderator

      Comment

      • aktar
        New Member
        • Jul 2006
        • 105

        #4
        Hi,

        to send html in an email, you need to have the right header when calling the mail() function. Have a look at the following code (from the PHP manual) for guidance.

        [PHP]<?php
        // multiple recipients
        $to = 'aidan@example. com' . ', '; // note the comma
        $to .= 'wez@example.co m';

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

        // message
        $message = '
        <html>
        <head>
        <title>Birthd ay 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 <mary@example.c om>, Kelly <kelly@example. com>' . "\r\n";
        $headers .= 'From: Birthday Reminder <birthday@examp le.com>' . "\r\n";
        $headers .= 'Cc: birthdayarchive @example.com' . "\r\n";
        $headers .= 'Bcc: birthdaycheck@e xample.com' . "\r\n";

        // Mail it
        mail($to, $subject, $message, $headers);
        ?> [/PHP]

        Regards

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          You are too quick! The code that was presented (in that awful format) shows, when run, just a number of instructions on how to make an email message. And it is also incorrect (see line 19). This is the result of running that html code
          Code:
          Code: ( php )
             1.      $to ="$_POST[email_addr]";
             2.      $subject = "Site Registration Confirmation";
             3.      $message = '
             4.  
             5.
             6.   
             7.
             8.
             9.
            10.      href=http://www.website.com/confirm.php?c='.$confirmationCode.'>http://www.website.com/confirm.php?c='.$confirmationCode.'
            11.
            12.      ';
            13.      $headers = "MIME-Version: 1.0\n";
            14.      $headers .= "Content-type: text/html; charset=iso-8859-1\n";
            15.      $headers .= "X-Priority: 3\n";
            16.      $headers .= "X-MSMail-Priority: Normal\n";
            17.      $headers .= "X-Mailer: php\n"
            18.      $from = "me@example.com";
            19.      $headers = "From: $from";    [B]// this is an error![/B]  
            20.       
            21.      mail($to,$subject,$message,$headers);
          Now my question to the OP hamsika is: what do you want with this, or, what is your problem/question?

          Ronald
          Last edited by ronverdonk; Mar 29 '08, 02:32 PM. Reason: code reformat

          Comment

          Working...