Some times ago I made a contact form to send email.
I had this:
If ($validity !='Good@Ripsi'){ $to = "contact-us@xx-xxxx.com"; $subject = "xx xxxx new Subscriber"; $email_address = htmlentities($_GET['email_address']); $headers = "xxxxxxxxxx" . "rn" . mail($to,$subject,$email_address,$headers); header("Location: index.php"); }
And that worked fine. After I read that although I don’t plan to send thousands of Newletters it would be better to use PHPmailer else it could be seen as spam and be blocked. I don’t understand much about those mailing things. So I read a tutorial and it works just fine but for one thing: htmlentities doesn’t do the job anymore and all <br>
are ignored at reception.
I checked that : $mail->IsHTML(true);
Help would be greatly appreciated.
Here is the code using PHPMailer:
<?php require "phpmailer/PHPMailer/PHPMailerAutoload.php"; define("DB_HOST","localhost"); define("DB_USERNAME","xxxx_xxxx"); define("DB_PASSWORD","xxxx"); define("DB_NAME","xxxxxx"); $conn = mysqli_connect(DB_HOST,DB_USERNAME,DB_PASSWORD,DB_NAME) or die (mysqli-error()); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } function smtpmailer($to, $from, $from_name, $subject, $body) { $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Host = 'mail.xxxxx.com'; $mail->Port = 465; $mail->Username = 'newsletter@xxxxx.com'; $mail->Password = 'xxxxxxx'; $mail->IsHTML(true); $mail->From="newsletter@xxxx.com"; $mail->FromName=$from_name; $mail->Sender=$from; $mail->AddReplyTo($from, $from_name); $mail->Subject = $subject; $mail->Body = $body; $mail->AddAddress($to); if(!$mail->Send()) { $error ="Error Ocured..."; return $error; } else { $error = "Please wait!! Your email is being sent... "; return $error; } } $from = 'newsletter@ts-ripsi.com'; $name = 'xxxxxxx T & S'; $subj = 'Newsletter from xxx and xxxx'; $msg = htmlentities($_GET['message']); $sqli = "SELECT ID, Email FROM mailing_addresses"; $record = mysqli_query($conn, $sqli); while ($row = mysqli_fetch_array($record)) { $to = $row['Email']; $error=smtpmailer($to,$from, $name ,$subj, $msg); } header("Location: index.php"); ?>
Advertisement
Answer
I hadn’t understood the use of IsHTML
. In this case it had to be set to false
.