I am doing a mail sent function from a contact form inside a Slim 3 project.
I get the name, email and message field data from $request->getParams() and then place it to an $email_message to send the information directly to my email. And the email was not delivered.
Funny thing is, without the getParams() data (I just replace it with any string), the email is delivered and i receive it. So probably the mail syntax is right and email is enabled on my hosting.
And if i echoed the message right before the mail() code, it print out the message correctly, so data from the form is received.
So I could not figure out what is going wrong here.
I try to use print_r(error_get_last()) but it only returns a blank page.
Please somebody can help? Thanks a lot!
My code:
$data = $request->getParams();
$name = $data['name'];
$email_from = $data['email'];
$message = $data['message'];
$email_message = "Name: ".$name."Message: ".$message;
$email_to = "myemail@email.com";
$email_subject = "Message from website";
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$send = mail($email_to, $email_subject, $email_message, $headers);
if($send)
{
echo 'Sent!';
} else {
print_r(error_get_last());
}
die();
UPDATED: now it prints out 'Sent!', and still i don't get any email to my email address.
For someone that mark this as duplicate, i also read that answer but not successful. This issue is different because it DID send email successully without data passed from the contact form, it only gets problem when there is data from getParams() added. So i hope somebody who is experience in Slim or PHP can help. Please don't just mark as duplicate if you don't really understand the question.