0

I'm using the Pear Mail Package to send an e-mail via G-Mail (using SMTP) for a website I'm developing. When someone registers with the website, the user must first click a link in the confirmation e-mail they receieve before their account is created. The problem i'm having is that the URL I embed in the e-mail is appearing literally as I typed it (with HTML tags displayed), i.e.

<a href = '...'>...</a>

and not as a clickable URL. Any suggestions on how I can make the url clickable? My code is more or less the same as the following question: Send email using the GMail SMTP server from a PHP page

<?php

require_once "/Mail/Mail-1.2.0/Mail.php";
require_once "/Mail/Mail-1.2.0/Mail_Mime-1.8.5/Mail/mime.php";

$from = "XYZ <XYZ.gmail.com>";
$email = $_GET['e'];
$to = $email;
$subject = "XYZ - Registration";
$body = "<html><body>Hi " . $_GET['f'] . ",\n\nThank You For Registering With XYZ\n\nPlease Click The Following Link To Confirm Your Account: <a href = 'www.test.com'>www.test.com</a></body></html>";
$crlf = "\n";

$mime = new Mail_mime($crlf);
$mime->setHTMLBody($body);
$body = $mime->get();

$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "XYZ";
$password = "XYZPassword";

$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)   );

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) 
{

    echo("<p>" . $mail->getMessage() . "</p>");

} 

else 
{

    echo("<p>Message successfully sent!</p>");

}

?>

Any help is much appreciated,

Thanks.

Community
  • 1
  • 1
slickboy
  • 451
  • 2
  • 8
  • 24

2 Answers2

1

Thanks to @andrewsi For His Help. Just Had To Make Some Minor Tweeks To Make His Example Work With G-Mail.

<?php

require_once "/Mail/Mail-1.2.0/Mail.php";
require_once "/Mail/Mail-1.2.0/Mail_Mime-1.8.5/Mail/mime.php";

$from = "XYZ <XYZ.gmail.com>";
$email = $_GET['e'];
$to = $email;
$subject = "xyz - Registration";
$body = "<html><body>Hi " . $_GET['f'] . ",\n\nThank You For Registering With xyz\n\nPlease Click The Following Link To Confirm Your Account: <a href = 'www.test.com'>www.test.com</a></body></html>";

$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "XYZ";
$password = "XYZPassword";

$crlf = "\n";
$hdrs = array(
              'From'    => $from,
              'Subject' => $subject
              );

$mime = new Mail_mime(array('eol' => $crlf));

$mime->setHTMLBody($body);

$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('smtp', array('host' => $host, 'port' => $port, 'auth' => true, 'username' => $username, 'password' => $password)    );
$mail->send($to, $hdrs, $body);

if (PEAR::isError($mail)) 
{

    echo("<p>" . $mail->getMessage() . "</p>");

} 

else 
{

    echo("<p>Message successfully sent!</p>");

}


?>
slickboy
  • 451
  • 2
  • 8
  • 24
0

Have a look at the PEAR manual page:

<?php

include 'Mail.php';
include 'Mail/mime.php' ;

$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = '/home/richard/example.php';
$crlf = "\n";
$hdrs = array(
              'From'    => 'you@yourdomain.com',
              'Subject' => 'Test mime message'
              );

$mime = new Mail_mime(array('eol' => $crlf));

$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file, 'text/plain');

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory('mail');
$mail->send('postmaster@localhost', $hdrs, $body);

?> 

If you don't explicitly tell it to, it assumes that you're sending a plain text email, and so your links aren't parsed by the receiving client.

andrewsi
  • 10,807
  • 132
  • 35
  • 51
  • Thanks @andrewsi This Led Me In The Right Direction. Just Had To Tweek It Slighlty To Work With G-Mail. Many Thanks – slickboy Sep 11 '12 at 14:28