jeudi 28 juillet 2016

PHP Sending Email Comma error

I am having trouble with sending emails through PHP.

So I have a form which submits to a PHP script which sends an email:

<?php

    $to  = "myemail@email.com"; 
    $subject = "[Contact Form]";
    $body    = "Someone has sent a new message from the contact form. \n \n  Message from: " . $_POST["name"] . "\n Contact Number: ".  $_POST["contactNumber"] ."\n Email: ". $_POST["email"] ."\n \n Message: ". (string)$_POST["message"]; 

    if (mail($to, $subject, $body)) {
        echo ("<p>Email successfully sent!</p>");
    } else {
        echo ("<p>Email delivery failed…</p>");
    }


?>

And the email is sent fine when for example the message is one line such as:

"Hi there how is it going?"

And fine if it is multiple lines such as

"Hi there

how is it going?"

But when I try and type a message with a comma such as

Hello there,

how is it going?

It fails?

Is there a way I can just treat the whole thing as a string possibly? Would this also fail on any other characters or is this issue just because of the way I am writing the PHP script?

This might be an obvious fix but I am new to PHP so apologies! I have tried looking around for an answer but nothing seems to fix what I am looking for.

Thanks for any help!




Aucun commentaire:

Enregistrer un commentaire