0

私は Pear Mail Package を使用して、開発中の Web サイトに G-Mail (SMTP を使用) 経由で電子メールを送信しています。Web サイトに登録する場合、ユーザーは、アカウントを作成する前に、受信した確認メールのリンクをクリックする必要があります。私が抱えている問題は、電子メールに埋め込んだ URL が、入力したとおりに (HTML タグが表示されて) 文字どおりに表示されることです。つまり、

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

クリック可能な URL ではありません。URLをクリック可能にする方法について何か提案はありますか? 私のコードは、次の質問とほぼ同じです: PHP ページから GMail SMTP サーバーを使用してメールを送信する

<?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>");

}

?>

どんな助けでも大歓迎です、

ありがとう。

4

2 に答える 2

1

@andrewsiの助けに感謝します。彼の例を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>");

}


?>
于 2012-09-11T14:33:30.090 に答える
0

PEARのマニュアルページを見てください:

<?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);

?> 

明示的に指定しないと、プレーン テキストの電子メールを送信していると見なされるため、リンクは受信クライアントによって解析されません。

于 2012-09-11T13:52:47.443 に答える