Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Pear邮件包-在电子邮件正文文本中嵌入URL_Php_Email_Gmail_Pear - Fatal编程技术网

Php Pear邮件包-在电子邮件正文文本中嵌入URL

Php Pear邮件包-在电子邮件正文文本中嵌入URL,php,email,gmail,pear,Php,Email,Gmail,Pear,我正在使用Pear邮件包通过G-Mail(使用SMTP)为我正在开发的网站发送电子邮件。当有人向网站注册时,用户必须先单击他们收到的确认电子邮件中的链接,然后才能创建帐户。我遇到的问题是,我在电子邮件中嵌入的URL在我键入它时(显示HTML标记)会出现,即 而不是作为一个可点击的URL。关于如何使url可点击,有什么建议吗?我的代码与以下问题大致相同: 非常感谢您的帮助 谢谢。看一下: 如果您没有明确告诉它,它会假定您正在发送纯文本电子邮件,因此接收客户端不会解析您的链接。感谢@an

我正在使用Pear邮件包通过G-Mail(使用SMTP)为我正在开发的网站发送电子邮件。当有人向网站注册时,用户必须先单击他们收到的确认电子邮件中的链接,然后才能创建帐户。我遇到的问题是,我在电子邮件中嵌入的URL在我键入它时(显示HTML标记)会出现,即


而不是作为一个可点击的URL。关于如何使url可点击,有什么建议吗?我的代码与以下问题大致相同:


非常感谢您的帮助

谢谢。

看一下:



如果您没有明确告诉它,它会假定您正在发送纯文本电子邮件,因此接收客户端不会解析您的链接。

感谢@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>");

}


?>


您是以HTML电子邮件还是纯文本电子邮件的形式发送电子邮件?我假设它是为纯文本设置的。它是SMTP,所以我猜它不支持HTML标记。你可以通过SMTP发送HTML电子邮件-你只需要在PHP中设置正确的设置。你想添加创建电子邮件的代码吗?谢谢adrewsi…我在编辑问题时添加了它。谢谢@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>";
$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>");

}

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

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

}


?>