HTML链接在wp邮件中不起作用

时间:2018-07-25 04:16:20

标签: wordpress

我已经设置了wp邮件功能,并且在正文上有一个类似

的链接
$to = $email;
$subject = "Payment Receipt - ".$fname.' '.$lname.' - '.date("m-d-Y"); 
$bodyadmin = "<html><head><title></title></head><body>Thank you for your 
payment please click <a href='https://www.google.com/'>Here</a></body> 
</html>";
$headersadmin  = 'MIME-Version: 1.0' . "\r\n";
$headersadmin .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersadmin .= 'From: ABC <abc@abc.com>' . "\r\n";
$headersadmin .= 'Cc: abc@abc.com' . "\r\n";
wp_mail( $to, $subject, $bodyadmin, $headersadmin );

但是,当我尝试发送邮件时,邮件不会发送。谁能告诉我为什么它不起作用?

4 个答案:

答案 0 :(得分:0)

Try changing your body to

$bodyadmin = "<h3>Thank you for your 
payment please click <a href='https://www.google.com/'>Here</a></h3>";

And it is good to use array type for headers as it will improve the clarity of your code and make it less error prone. For eg.

$headers[] = 'From: Me Myself <me@example.net>';
$headers[] = 'Cc: John Q Codex <jqc@wordpress.org>';
$headers[] = 'Cc: iluvwp@wordpress.org'; // note you can just use a simple email address

答案 1 :(得分:0)

You can try following Example and try it:

$to = 'sendto@example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');

wp_mail( $to, $subject, $body, $headers );

答案 2 :(得分:0)

I don't see any error in code and it does work on my side. (screenshots available below for reference)

Problem:

The SMTP is not configured for your wordpress site. Please try any plugin to configure SMTP OR follow this tutorial.

Code:

enter image description here

Mailbox:

enter image description here

答案 3 :(得分:0)

you have concatenation bug in your code, use this

$to = $email;
$subject = "Payment Receipt - ".$fname." ".$lname." - ".date('m-d-Y'); 
$bodyadmin = "<html><head><title></title></head><body>Thank you for your 
payment please click <a href='https://www.google.com/'>Here</a></body> 
</html>";
$headersadmin  = 'MIME-Version: 1.0' . "\r\n";
$headersadmin .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headersadmin .= 'From: ABC <abc@abc.com>' . "\r\n";
$headersadmin .= 'Cc: abc@abc.com' . "\r\n";
wp_mail( $to, $subject, $bodyadmin, $headersadmin );