SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2010
    Posts
    167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Formatting a PHP Variable

    Hi there,

    I have a script that people can use to refer a page to their friends via email and I wanted to spice up the email a bit so that when the recipient receives it, they see more than just plain text.

    Here is the script:

    PHP Code:
    <?php

    if (isset($_POST['youremail']))
    {

    $url "http://ivegotkids.com/aries";
    $email $_POST['email'] ;
    $youremail $_POST['youremail'] ;
    $igkmail 'noreply@ivegotkids.com' ;
    $sender $_POST['yourname'] ;
    $recipient $_POST['friendname'] ;
    $subject 'I thought you might like this.';
    $comment $_POST['message'] ;
    $message "Hi "$recipient ". Your friend " $sender " saw this horoscope on ivegotkids.com and thought you might find it interesting: (" $url ") 
    "
    $sender ." included this message: " $comment ;
    $from "" $sender " (via I\'ve Got Kids) <" $igkmail ">";
    $headers "From: " $from;
    mail($email$subjectstripslashes($message), $headers);
    echo 
    "Thank you! Your mail has been sent.";
    }
    else
    {
    echo 
    '
    <img src="http://ivegotkids.com/wp-content/themes/thepink/images/logo.png">
    <br /><br />
    <span class="formtitle">Send "<span class="pagetitle">I\'ve Got Kids!: Aries"</span> to a friend by e-mail.</span>
    <br />
    Fill out the form below and click on submit to send this to your friend.
    <br /><br />
    <form method="post">
    Your Name: <input type="text" name="yourname" length="40"/> <br />
    Your Email: <input type="text" name="youremail" length="50"/> <br /><br>
    Friend\'s Name: <input type"text" name="friendname" length="40" /><br>
    Friend\'s E-Mail: <input type="text" name="email" length="50" /><br /><br />
    Include a message from you:<br />
    <textarea rows="4" cols="50" name="message"> </textarea><br /><br />
    <input type="submit" value="Send To Friend">
    </form>'
    ;
    }

    ?>
    The bit I need to change is this:

    PHP Code:
    $message "Hi "$recipient ". Your friend " $sender " saw this horoscope on ivegotkids.com and thought you might find it interesting: (" $url ") 
    "
    $sender ." included this message: " $comment 
    That is what the recipient receives. I need to spice this up a little. Add some formatting and a logo. How do I include HTML and Inline CSS Statements into this variable without breaking the PHP or having it render as text the other end? I tried to add an <img src> to the beginning but it literally printed out the code in the email rather than displaying the image.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to send headers with your email.

    Example:

    PHP Code:
    $headers  "MIME-Version: 1.0" "\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" "\n";
    $headers .= "From: " $from
    Also you can add html email and a text version of your email. So people who cant receive html mail, still can read the message.

    There are also some nice classes around who will send your emails in nice html format. Look around for them in google.


Bookmarks

Posting Permissions

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