SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Html in an email?

    Hello I've googled everywhere to try to fix this problem. No luck. Can anyone tell me why html isn't reading right in the email? Its only showing in the email like this: <span> and so on. Thank you very much.


    PHP Code:
    <?php
    ?>
    <form action="<?php $_SERVER['PHP_SELF'] ;?>" method='post'>
    <input type='text' name='username' size=15>
    <span>User name</span><br />
    <input name='email' size=15>
    <span>Email</span><br />
    <input type='submit' name="submit" value='Submit'><br /><br />
    </form>
    <?php 
    if (isset($_POST['submit'])) {
    $username $_POST['username'] ; 
    $pemail $_POST['email'] ; 
    $from 'noreplysupport@somesite.com';
    $subject "Validation Email" 
    $messageproper "<span style=\"font-family:arial,sans-serif;font-size:14px\">Just click on the following link to validate your email.</span> 
    <a href=\"http://www.example.com/validate.php?username=
    $username\" target=\"blank\">Validate</a>";
    $headers "MIME-Version: 1.0" "\r\n";
    $headers .= "Content-type:text/html;charset=iso-8859-1" "\r\n";
    $headers "From: <$from>\r\n";
    $headers .= "Reply-To: ".preg_replace('/[\r\n]+/'' '$from)."\r\n";
    mail($pemail$subject$messageproper$headers);

    ?> 

    This doesn't work either: 
    $messageproper = "<html>
    <body>
    <div>
    <span style='font-family:arial,sans-serif;font-size:14px'>Just click on the following link to validate your email. </span> 
    <a href='http://www.example.com/validate.php?username=$username'  target='blank'>Validate</a></div></body></html>";
    Last edited by 1Jen; Aug 12, 2007 at 21:44.

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Can you please show me an example of the output message?

    Thanks.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not to use PEAR::Mail_Mime or PHPMailer?

    By the way, as far as I remember, there must be empty line between headers and body:

    From: user@site.com\r\n
    To: other_user@site.com\r\n
    Subject:test\r\n
    \r\n
    Message goes here

    Try adding one more \r\n after your headers. And take a look at the resulting headers. Simply echo them (or output to file) and see, if they are OK.

    But it's better to use special classes (see above).

  4. #4
    SitePoint Evangelist BJ Duncan's Avatar
    Join Date
    Jun 2007
    Location
    Bowen Mountain, NSW
    Posts
    490
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $headers "From: <$from>\r\n"
    Shouldn't it be:
    PHP Code:
    $headers .= "From: <$from>\r\n"
    Regards,
    BJ Duncan

  5. #5
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, I really appreciate the help, I'm stuck. Arkinstall what do you mean by the output message? It goes straight into an email with the message I include going in the email above, in the $messageproper. I'm not using PEAR::Mail_Mime or PHPMailer because aren't we able to do it ourselves without using those? So far still not working.

  6. #6
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I think BJ_Duncan's solution should have worked.

    By the output message, I meant what email looks like.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  7. #7
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BJ Duncan told you where you have mistake. If it is not working, then give us output(var_dump() or print_r()) of $pemail, $subject, $messageproper, $headers.
    And output of the result email please.

    [OFFTOPIC]
    Quote Originally Posted by 1Jen View Post
    I'm not using PEAR::Mail_Mime or PHPMailer because aren't we able to do it ourselves without using those? So far still not working.
    Yes, we are able. We can invent a wheel also
    Why not using ready classes if they are working well. By the way, sending email via SMTP-server works faster. Developing emailing solution yourself, you'll have to change a number of code to make it work with SMTP-server. If using Mail_Mime+Mail, you change only a bit of code.
    Plus you get an instrument to send HTML message with images (or you'll need to add CID yourself) and with attachments easily.

    RESUME: Developing own mailing solution is good only for educational purposes. For using in real applications ready classes are better. Sure, only well-developed classes. PEAR's classes are good.
    [/OFFTOPIC]

  8. #8
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not using PEAR::Mail_Mime or PHPMailer because aren't we able to do it ourselves without using those?
    You are welcome to try, but the reason so many experienced coders have settled into using a class such as PHPMailer, is because sending mail with PHP ceased to be as easy as just using the mail function, some time ago.

    Getting around spam filters, has become too much of a pain. we just use what works and move on. By using a class, you can use it over and over and never have to deal with email headers again. That much less to worry about.

    You don't have to write everything yourself. I know that that is tempting, but there is a lot of good re-usable code out there to save time and money, why not use it?

  9. #9
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well gosh ok, always seems like someone has to take our fun away so we can't do it ourselves, then they'll probably try to charge us later for it if they aren't already right now. I'll look into all your tips and see what they all are, thanks for the great suggestions. I'll also let you know if I get this particular problem fixed so far I'm doing something wrong with duncans but I'll try more.

  10. #10
    SitePoint Wizard Hammer65's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln Nebraska
    Posts
    1,161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Didn't mean to sound egotistical or anything, it's just that there is a reason such classes are used in so many PHP based open source projects.

    Most other developers that i know that have been doing PHP for any longer than 2 years professionally use them too.

    I've already been through the mail isn't sending or mail isn't getting there or mail is ending up in the spam pile problems with my own code and other's. Because of that my best advice to you is to use something that is pre-written.

    Same with something like PDF generation. If that area of coding interests you, and you don't mind wading through the PDF format documentation, then doing it yourself might be rewarding, but otherwise, there are a lot of good pre-written classes that do PDF generation, that you could use and get on with something more rewarding like finishing your application or site ahead of schedule.

  11. #11
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm new to php programing, but here's some code that I put togehter, which works:

    PHP Code:
    <?php

    $headers  
    'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
    $headers .= 'From: <add email here>' ."\r\n" .
            
    'Reply-To: <add email here>';
     
    $email_to '<add email here>';
    $subject "Email Subject Goes Here";
     
    $body "
    <head>
    <meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"UTF-8\">
    <style type=\"text/css\">
    /* Add styling */
    </style>
    </head>
    <body>

    Body of email starts here

    </body>
    </html>
    "
    ;

    mail($email_to$subject$body$headers);
    ?>

  12. #12
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I love you all! That teensy little dot is all it needed, sick I missed that and went to so much work hitting my head up against a wall for a few days. Turned out I had to open a brand new page in mozilla, it wouldn't take the new email change if I just refreshed the page. Thanks everybody so much for helping me with that.

    You didn't sound arrogant at all only helpful. I've just never had coders tell I might have better luck not doing it myself. I want to be sure why theirs wouldn't read as spam but mine would. But I'll fully look into it to see why they have better luck with theirs than I would with mine.

    Best wishes, and thanks oodles!! Jen


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
  •