refiking Posted January 2, 2008 Share Posted January 2, 2008 I want to send a link through email using php. I already have the email script written. I just need to know what is the line of code needed to send a link. For example. Here is what the body of the message looks like $one = "Hello!.$bfn.\n\n Welcome to The Refiking"; $two = "\n\n When you login, you will be asked to change your password immediately."; $three = "<a href="www.yahoo.com">Login Now</a>"; $message = $one . $two; What do I need to change $three to? Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/ Share on other sites More sharing options...
tibberous Posted January 2, 2008 Share Posted January 2, 2008 It depends on whether or not the mail service they are using allows html to be sent in emails. I would just sent the link as plain text. Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428336 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 If you want to send your email in html you'll have to adjust your headers to do so. Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428338 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 Which headers do I adjust? Can you provide a quick example? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428340 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 Here's a script I wrote for sending html emails. // Send HTML Email // This function is used for emailing a standardized form $headers = "From: $from \r\n"; $headers .= "Cc: $cc \r\n"; $headers .="Bcc: $bcc \r\n"; $boundary = uniqid(md5(date("YmdHis"))); $headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary\r\n\r\n"; //message to people with clients who don't understand MIME $headers .= "This is a MIME encoded message.\r\n\r\n"; //HTML version of message $headers .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("$html")); $mailSucceed = @mail($to, $subject, "", $headers); if($mailSucceed){ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Sent Successfully</p>"; }else{ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Failed to Send</p>"; } This requires a $subject, $from, $to, $bcc, $cc, and $html variables before running. The $html would be the html of the email being sent. Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428345 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 OK. So, would I make $html=www.yahoo.com? Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428359 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 No html would be the entire message. $one = "Hello!.$bfn.\n\n Welcome to The Refiking"; $two = "\n\n When you login, you will be asked to change your password immediately."; $three = "<a href="www.yahoo.com">Login Now</a>"; $html= $one . $two . $three; Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428365 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 Did this work for you then? If it did could you click "Topic Solved" Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428415 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 Parse error: parse error, unexpected T_STRING in /home/public_html/tp/mail.php on line 9 This is line 9: $three = "<a href="www.yahoo.com">Login Now</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428557 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 You need to escape the double quotes. $three = "<a href=\"www.yahoo.com\">Login Now</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428559 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 The line in the email read like this: When you login, you will be asked to change your password immediately.<a href="www.yahoo.com">Login</a> Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428645 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 Please post your code so I can take a look at it. Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428647 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 <?php $bfn = "Joe"; $user = 1; $pass = 123; $to = "johndoe@gmail.com"; $subject = "Test mail"; $one = "Hello $bfn!\n\n This is a verification email.."; $two = "\n\n When you login, you will be asked to change your password immediately."; $three = <a href="www.yahoo.com">Login</a>; $message = $one . $two . $three; $from = "donotreply@refiking.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428652 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 <?php $bfn = "Joe"; $user = 1; $pass = 123; $to = "johndoe@gmail.com"; $subject = "Test mail"; $one = "Hello $bfn!\n\n This is a verification email.."; $two = "\n\n When you login, you will be asked to change your password immediately."; $three = "<a href=\"www.yahoo.com\">Login</a>"; $message = $one . $two . $three; $from = "donotreply@refiking.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> But note you must use the code I provided above in my previous posts to send this email as html, otherwise you'll see the <a href ... etc If you don't care about sending it as an html email have $three look like this: $three = "Login at www.yahoo.com"; Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428658 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 Where should I place the code you gave me? Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428663 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 Replace your code with this: // Send HTML Email // This function is used for emailing a standardized form $bfn = "Joe"; $to = "johndoe@gmail.com"; $cc = ""; $bcc = ""; $subject = "Test Mail"; $one = "Hello $bfn!\n\n This is a verification email.."; $two = "\n\n When you login, you will be asked to change your password immediately."; $three = "<a href=\"www.yahoo.com\">Login</a>"; $message = $one . $two . $three; $from = "donotreply@refiking.com"; $headers = "From: $from \r\n"; $headers .= "Cc: $cc \r\n"; $headers .="Bcc: $bcc \r\n"; $boundary = uniqid(md5(date("YmdHis"))); $headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary\r\n\r\n"; //message to people with clients who don't understand MIME $headers .= "This is a MIME encoded message.\r\n\r\n"; //HTML version of message $headers .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("$html")); $mailSucceed = @mail($to, $subject, "", $headers); if($mailSucceed){ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Sent Successfully</p>"; }else{ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Failed to Send</p>"; } Let me know if it works Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428675 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 This is what the email reads: Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: base64 Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428684 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 Woops that makes sense, change this $message = $one . $two . $three; to $html = $one . $two . $three; Let me know if it still gives you the same error Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428688 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: base64 SGVsbG8gSm9lIQoKIFRoaXMgaXMgYSB2ZXJpZmljYXRpb24gZW1haWwuLgoKIFdoZW4geW91IGxv Z2luLCB5b3Ugd2lsbCBiZSBhc2tlZCB0byBjaGFuZ2UgeW91ciBwYXNzd29yZCBpbW1lZGlhdGVs eS48YSBocmVmPSJ3d3cueWFob28uY29tIj5Mb2dpbjwvYT4= Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428706 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 You used my code exactly? Can you please post your code so I review it. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428709 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 <?php // Send HTML Email // This function is used for emailing a standardized form $bfn = "Joe"; $to = "user@refiking.com"; $cc = ""; $bcc = ""; $subject = "Test Mail"; $one = "Hello $bfn!\n\n This is a verification email.."; $two = "\n\n When you login, you will be asked to change your password immediately."; $three = "<a href=\"www.yahoo.com\">Login</a>"; $html = $one . $two . $three; $from = "donotreply@refiking.com"; $headers = "From: $from \r\n"; $headers .= "Cc: $cc \r\n"; $headers .="Bcc: $bcc \r\n"; $boundary = uniqid(md5(date("YmdHis"))); $headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary\r\n\r\n"; //message to people with clients who don't understand MIME $headers .= "This is a MIME encoded message.\r\n\r\n"; //HTML version of message $headers .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("$html")); $mailSucceed = @mail($to, $subject, "", $headers); if($mailSucceed){ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Sent Successfully</p>"; }else{ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Failed to Send</p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428713 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 The following works for me, I just tested this script Copy it exactly as it, changing only the email fields. <? // Send HTML Email // This function is used for emailing a standardized form $bfn = "Joe"; $to = "joe@gmail.com"; $from = "donotreply@refiking.com"; $cc = ""; $bcc = ""; $subject = "Test Mail"; $one = "Hello $bfn!\n\n This is a verification email.."; $two = "\n\n When you login, you will be asked to change your password immediately."; $three = "<a href=\"www.yahoo.com\">Login</a>"; $html = $one . $two . $three; $headers = "From: $from \r\n"; $headers .= "Cc: $cc \r\n"; $headers .="Bcc: $bcc \r\n"; $boundary = uniqid(md5(date("YmdHis"))); $headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary\r\n\r\n"; //message to people with clients who don't understand MIME $headers .= "This is a MIME encoded message.\r\n\r\n"; //HTML version of message $headers .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $headers .= chunk_split(base64_encode("$html")); $mailSucceed = @mail($to, $subject, "", $headers); if($mailSucceed){ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Sent Successfully</p>"; }else{ echo "<p style=\"color: #336699; font-weight: bold;\">Mail Failed to Send</p>"; } ?> This code should work, I just tested it. Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428722 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 I copied it exactly and only changed the email field and this is what I got: Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: base64 SGVsbG8gSm9lIQoKIFRoaXMgaXMgYSB2ZXJpZmljYXRpb24gZW1haWwuLgoKIFdoZW4geW91IGxv Z2luLCB5b3Ugd2lsbCBiZSBhc2tlZCB0byBjaGFuZ2UgeW91ciBwYXNzd29yZCBpbW1lZGlhdGVs eS48YSBocmVmPSJ3d3cueWFob28uY29tIj5Mb2dpbjwvYT4= Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428725 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 Which version of php are you using? Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428735 Share on other sites More sharing options...
refiking Posted January 2, 2008 Author Share Posted January 2, 2008 4.1 Quote Link to comment https://forums.phpfreaks.com/topic/84144-email-link/#findComment-428743 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.