Jump to content

Recommended Posts

When a user registers i send them an activation email but my mail function doesn't work properly even though i got it from the php website.

 

The headers is my problem they won't work so <br> just comes through as text rather than actually using it as html.

 

My script:

 

<?php
        $subject = "Welcome";
        $headers = 'From: Company Name';
        $headers .= 'Reply-To: '.$Domain;
        $headers .= 'MIME-Version: 1.0';
        $headers .= 'Content-type: text/html; charset=iso-8859-1';
        $message =  'Thank you for registering! <br><br>
        To activate your account, please visit this link:';
        $message = $message. "<br><br> ".$Link;
        $message = $message. '<br><br> Your username is: '.$Username.' <br>You password is: '.$Password2.' !';
        mail($Email, $subject, $message, $headers);    
?>

 

What am i doing wrong with my headers?

Link to comment
https://forums.phpfreaks.com/topic/203151-mail-not-working/
Share on other sites

          $subject = "Welcome";
        $headers = 'From: Company Name';
        $headers .= 'Reply-To: [email][email protected][/email]';
        $headers .= 'MIME-Version: 1.0';
        $headers .= 'Content-type: text/html; charset=iso-8859-1';
        $message =  "Thank you for registering!.\n\n";
        $message = $message. "To activate your account, please visit this link:.\n\n";
        $message = $message. "[url=http://www.google.com]www.google.com[/url].\n\n";
        $message = $message. 'Your username is: '.$Username.' <br>You password is: '.$Password2.' !';
        mail($Email, $subject, $message, $headers);

 

That's for the breaks I believe.

Link to comment
https://forums.phpfreaks.com/topic/203151-mail-not-working/#findComment-1064411
Share on other sites

Where is the variable $Email being set? That should be the email address of the recipient.

 

Ken

 

That is further up the script. I do recieve the email but it comes out showing the "<br>" rather than acting as HTML.

 

@Karl the method you used isn't what im trying to do sorry, im trying to allow the email to use HTML so itll convert "<br>" into new lines.

Link to comment
https://forums.phpfreaks.com/topic/203151-mail-not-working/#findComment-1064412
Share on other sites

Oh in that way, you're missing <html>, <head> and <body> tags. That's basic HTML.

 

        $message =  '<html>
                     <head>
                        <title>Welcome</title>
                     </head>
                     <body>
                        Thank you for registering!<br/><br/>
                        To activate your account, please visit this link:<br/>
                        <a href="link">Link</a><br/><br/>
                        Your username is: '.$Username.' <br>You password is: '.$Password2.' !
                     </body>
                     </html>';

 

Something like that.

Link to comment
https://forums.phpfreaks.com/topic/203151-mail-not-working/#findComment-1064413
Share on other sites

Each header line must be terminated by a \r\n (inside of double-quotes).

 

Also, your From: header must be an actual email address and it must be hosted at the sending mail server. The Reply-to: header must be an email address (it's not clear from the code you posted.)

Link to comment
https://forums.phpfreaks.com/topic/203151-mail-not-working/#findComment-1064415
Share on other sites

How come when i recieve emails from things like facebook in Gmail then it says "From : Facebook"

 

Rather than a website email ? The Reply to is "[email protected]" which isn't a real email address at my server cos people are not suppose to reply.

 

 

Edit the /r/n worked perfectly :) Thanks

Link to comment
https://forums.phpfreaks.com/topic/203151-mail-not-working/#findComment-1064418
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.