Reputation:
I am trying to use the mail function to send an email but can't seem to get my link to work. It is displaying as a string instead of a link.. I am not sure how to closed off the string quotation or what the correct format is....
$company = '[email protected]';
$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);
Upvotes: 0
Views: 773
Reputation:
It looks like your mail is not in HTML format. I suggest you start using PHPMailer: https://github.com/PHPMailer/PHPMailer It's really easy to use and In PHPMailer you can send HTML emails!
Here is their simple example:
<?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 = '[email protected]'; // 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('[email protected]', 'Mailer');
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
// 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}";
}
To install PHPMailer you can use composer. After installing composer you can install PHPMailer with composer like this:
composer require phpmailer/phpmailer
or download the files manually
Upvotes: 1
Reputation: 946
This will help your links work, as tag is html tag so mime type should be define html so it instruct that email will sent in html format.
$company = '[email protected]';
$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);
Hope it will help you.
Upvotes: 0