我正在尝试使用邮件功能发送电子邮件,但似乎无法使我的链接正常工作。它显示为字符串而不是链接。.我不确定如何关闭字符串引号或正确的格式。...
$company = 'pianocourse101@hotmail.com';
$subject = 'Account temporary suspended due to failed login attempts';
$mailTo = $row['user_email'];
$headers = 'From: '.$company;
$txt = "Hello ".$row['user_first']."" .$row['user_last']."! \n\n Your account has been temporary suspended because you or someone claiming to be you has failed to login into their account more than on more than five occasions. \n\n Please click on the following link to change your password so that you can login again <a href='reset.php'>Click here to reset your password </a>";
mail($mailTo, $subject, $txt, $headers);
答案 0 :(得分:1)
您的邮件似乎不是HTML格式。我建议您开始使用PHPMailer: https://github.com/PHPMailer/PHPMailer 它真的很容易使用,在PHPMailer中,您可以发送HTML电子邮件!
这是他们的简单示例:
void caller() {
std::vector<object*> objs{uniqueptr1.get(), uniqueptr2.get()};
foo(objs);
}
void foo(vector<object*>& shapes)
{
......//do something
}
要安装PHPMailer,可以使用composer。安装composer之后,您可以使用以下composer安装PHPMailer:
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
// Load Composer's autoloader
require 'vendor/autoload.php';
// Instantiation and passing `true` enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp1.example.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user@example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
$mail->Port = 587; // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients
$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // Add a recipient
$mail->addAddress('ellen@example.com'); // Name is optional
$mail->addReplyTo('info@example.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
// Attachments
$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
// Content
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
或手动下载文件
答案 1 :(得分:0)
您需要指定标题。因为您是以纯文本形式发送的。
<?php
$company = 'pianocourse101@hotmail.com';
$subject = 'Account temporary suspended due to failed login attempts';
$mailTo = $row['user_email'];
$headers = 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: ' . $company;
$txt = "Hello " . $row['user_first'] . "" . $row['user_last'] . "! \n\n Your account has been temporary suspended because you or someone claiming to be you has failed to login into their account more than on more than five occasions. \n\n Please click on the following link to change your password so that you can login again <a href='reset.php'>Click here to reset your password </a>";
mail($mailTo,$subject,$txt,$headers);
答案 2 :(得分:0)
这将帮助您的链接正常工作,因为标签是html标签,因此应将mime类型定义为html,以便指示电子邮件将以html格式发送。
$company = 'pianocourse101@hotmail.com';
$subject = 'Account temporary suspended due to failed login attempts';
$mailTo = $row['user_email'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: '.$company;
$txt = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div>';
$txt .= 'Hello '.$row['user_first'].' '.$row['user_last'].'!<br><br>Your account has been temporary suspended because you or someone claiming to be you has failed to login into their account more than on more than five occasions. <br><br> Please click on the following link to change your password so that you can login again <a href="reset.php">Click here to reset your password </a>';
$txt.=' </div>
</body>
</html>';
mail($mailTo, $subject, $txt, $headers);
希望它会对您有所帮助。