Jump to content

PHP function dies on carriage return


Macalou
 Share

Recommended Posts

I have created a simple contact form and it works beautifully, until a user enters more than one carriage return. For example, the following work and the PHP script functions as normal if the user were to enter the following:

Hi, there! I'd love to work with you! When are you available?

 - or -

Hi there!
I'd love to work with you! When are you available?

Either one of those land on the success page and I receive the email. However, if they enter a second carriage return to start a new paragraph, it causes the PHP script to run the die function. For example:

Hi there!

I'd love to work with you!

When are you available?

Is it something with the PHP coding? Or is there a function inside the HTML code that needs to allow for carriage returns? I am extremely new to coding, and I realize the PHP is basic, but it works for my needs.

Take a look.

HTML code for the form:

<form id="contact-form" method="post" action="mail.php" role="form">
    <div class="form-group">
        <label for="name">Call me...</label><br>
            <input type="text" class="form-control" placeholder="Ishmael. No? Okay. Enter your name here." id="name" name="name" style="width: 350px; padding: 7px; margin-bottom: 20px;">
    </div>
    <div class="form-group">
        <label for="email">You can find me @</label><br>
            <input type="email" class="form-control" placeholder="Email" id="email" name="email" style="width: 350px; padding: 7px; margin-bottom: 20px;" aria-describedby="emailHelp">
                <span id="emailHelp" class="form-text text-muted" style="display: none;">Please enter a valid e-mail address.</span>
    </div>
    <div class="form-group">
        <label for="message" style="vertical-align: top;">And here's what I'm thinking...</label><br>
            <textarea id="message" type="text" rows="10" cols="50" class="form-control" placeholder="Keep it brief. Or not. You have my undivided attention." name="message" aria-describedby="messageHelp"></textarea>
                <span id="messageHelp" class="form-text text-muted" style="display: none;">Please enter a message.</span>
    </div>
    <div class="text-center">
        <button type="submit" style="width: 90px; padding: 8px;">Send</button>
    </div>
</form>

 

PHP code is as follows:

<?php
if(isset( $_POST['name']))
$name = $_POST['name'];
if(isset( $_POST['email']))
$email = $_POST['email'];
if(isset( $_POST['message']))
$message = $_POST['message'];

$recipient = "maca@macaferguson.com";
$mailheader = "From: $email \r\n";
$content="From: $name \n Email: $email \n Message: $message \r\n";

mail($recipient, $mailheader, $subject, $message) or die("<h3><center>Well, that didn't go as planned. Please try again.</center></h3>");
header("Location: thank_you.html");
?>

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...