Can't send mail by mail()

My Code:

mail("mtucker18346@gmail.com", “Subject”, “This is my message”);

Does not send. I am using the free hosting, and according to both my new CPanel and the main website, I should be able to send.

I would put all the screenshots that I took for showing SendMail being enabled in CPanel, and the statistics showing that I have not sent a single SendMail yet (0% daily quota filled), but I’m just going to put the picture of the main website that says free hosting is supposed to have this functionality:

I had this same issue with this hosting before and was told that I needed to get professional version in order to get it to send faster. I’m not even worried about it sending faster, but sending at all would be helpful.

I don’t believe I did anything wrong with my code. I simplified it like crazy just to get it to work and it won’t work. Any help would be appreciated.

The mail() function works on free plan. However giant mail corporations such as Yahoo and Google have massive anti-spam filters in order to protect their clients from harassment.

There are more chances for your email to pass the ‘scam tests’ if you include proper headers in your mail() function. Try this code instead :wink:

<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

mail($to, $subject, $txt, $headers);
?> 

Please, replace all variables with proper values.

@NGiNX I have put in place the code recommended, and replaced the variables as instructed. How long would you recommend that I wait for the email to send then; again I am on the free version of the hosting.

I received the email within a few seconds.

I am also using a Gmail address.

I have not received any email.

Here is the entirety of my code now:

<?php

function saveMessage($name, $email, $phone, $message){
require("…/connect.php");
$q2=$db->prepare(“INSERT INTO mtd_msg (Name, Email, Phone, Message, Date) VALUES(’”.$name."’, ‘".$email."’, ‘".$phone."’, ‘".$message."’, NOW())");
$q2->execute();
$r2 = $q2->fetch();
}

saveMessage($_POST[‘name’], $_POST[‘email’], $_POST[‘phone’], $_POST[‘message’]);

$to = "mtucker18346@gmail.com";
$subject = “My subject”;
$txt = “Hello world!”;
$headers = “From: webmaster@MTDesigns.com” . “\r\n” . “CC: Copy@MTDesigns.com”;

mail($to, $subject, $txt, $headers);
?>

Because they denied me help on the mail() before, I’ve been saving any messages to a database table. I know that works because I see it when I refresh my database every time I test. However even though the INSERT works, the mail() still does not. :frowning:

Nevermind I found out the issue.

$r2 = $q2->fetch();

should never have been there.

1 Like

If you encounter any other problems, we’re here to help you out :wink:

1 Like