I’m using the script below to send emails, unfortunately, it’s not working on my webhosting uk account.
Their helpdesk are telling me that is might be due to the fact that they have deactivated php mail function.
So my question is: Is the code below using php mail function?
If this is the case, how difficult is it to make it “SMTP authentication” compliant?
Many thanks
<?php
$sendto = "myaddress@gmail.com";
$usermail = $_POST['email'];
$username = $_POST['name'];
$content = nl2br($_POST['msg']);
$subject = "New Message frm";
$headers = "From: " . strip_tags($usermail) . "\r\n";
$headers .= "Reply-To: ". strip_tags($usermail) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;charset=utf-8 \r\n";
$msg = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New message</h2>\r\n";
$msg .= "<p><strong>From:</strong> ".$username."</p>\r\n";
$msg .= "<p><strong>E-mail:</strong> ".$usermail."</p>\r\n";
$msg .= "<p><strong>Message:</strong> ".$content."</p>\r\n";
$msg .= "</body></html>";
if(@mail($sendto, $subject, $msg, $headers)) {
echo "true";
} else {
echo "false";
}
?>
If you want to make it SMTP compliant, then I suggest you go looking for the PHPMailer library, it’s just a couple of classes (you will only need one if I’m not mistaken), and it will make it SMTP compliant, and it’s much more recommended over using
mail().Also, try getting the @ out of the
mail()function, yes it is using@mail().Hope this helps. 🙂