Jump to content

Newbie who can't get his form to echo correctly


vincewentwrong

Recommended Posts

Hi there, I've been following a great tutorial on youtube which has helped my understand a lot of what's going on in PHP forms but I cannot for the life of me get it to work properly.

I've tested it online, it sends to my email address but it's either completely blank or comes up with the title of a single field. I've tried playing around with some variations a lot so it probably makes less sense than it did before.

Can anyone help me? I'd really like to know where I'm going wrong and my brain hurts now!

<?php

$to = 'MYEMAILADDRESS (Yes I know, I've taken it out)';
$subject = 'Enquiry';

$model = $_POST['model'];
$year = $_POST['year'];
$info = $_POST['info'];
$image = $_POST['image'];
$name = $_POST['name'];
$location = $_POST['location'];
$number = $_POST['number'];
$email = $_POST['email'];

$message = <<<EMAIL

$model
$year
$info
$image
$name
$location
$number
$email

EMAIL;

$header = '$model';

if($_POST){
    mail($to, $model, $year, $info, $image, $name, $location, $number,$email);
    $feedback = 'Thanks, we will get back to you shortly.';
}

?>


<div id="form">

<p id="feedback"><?php echo $feedback; ?></p>

<form action="?" method="post">

<ul>
<li>
    <label for="model"> System Brand / Model:</label>
    <input type="text" name="model" id="model" />
    </li>
    
<li>
    <label for="year">Year Of Manufacturer:<br />(If Known)</label>
    <input type="text" name="year" id="year" />
    </li>    
    
<li>
    <label for="info">Additional Information:</label>
    <textarea name="info" id="info"></textarea>
    </li>
    
<li>
    <label for="image">Upload an Image:</label>
    <input name="image" type="file" id="image" />
    </li>
    
<li>
    <label for="name"> Clinic Name:</label>
    <input type="text" name="name" id="name" />
    </li>

<li>
    <label for="location">Location:</label>
    <input type="text" name="location" id="location" />
    </li>

<li>
    <label for="number">Contact Number:</label>
    <input type="text" name="number" id="number" />
    </li>
    
<li>
    <label for="email">Email Address:</label>
    <input type="text" name="email" id="email" />
    </li>
</ul>

<input type="submit" name="submit" value="Send" />

</form>

</div>
 

Thanks!

Link to comment
Share on other sites

I can't understand this part

$message = <<<EMAIL

$model
$year
$info
$image
$name
$location
$number
$email

EMAIL;

$header = '$model';


what are you trying to do?

In case you want to add all those variables into the message variable you need to use dots to connect them or just double quotes around the whole thing. Same story with $header = '$model'; This will set the $header value to the text $model. if you want to set it to be equal to the model variable you need to either use double quotes or no quotes at all.
 
Link to comment
Share on other sites

If you don't understand it, probably best to learn about it instead of saying its wrong. That's HEREDOC syntax.

 

 

I can't understand this part

 

 

$message = <<<EMAIL

$model
$year
$info
$image
$name
$location
$number
$email

EMAIL;

$header = '$model';

what are you trying to do?

 

In case you want to add all those variables into the message variable you need to use dots to connect them or just double quotes around the whole thing. Same story with $header = '$model'; This will set the $header value to the text $model. if you want to set it to be equal to the model variable you need to either use double quotes or no quotes at all.

Link to comment
Share on other sites

OP: mail accepts specific arguments that you are not supplying. Read that and fix mail()

Also single quoted strings will not have variables parsed.

'$model' is the literal string of '$model'.

You go through the trouble of creating $message but never use it.

 

Edit: YAY MOBILE EDIT FINALLY.

Edited by Jessica
Link to comment
Share on other sites

<?php

$to = 'nick@photronics.co.uk';
$subject = 'Sales Enquiry';

$model = $_POST['model'];
$year = $_POST['year'];
$info = $_POST['info'];
$image = $_POST['image'];
$name = $_POST['name'];
$location = $_POST['location'];
$number = $_POST['number'];
$email = $_POST['email'];

$message = <<<EMAIL

$model
$year
$info
$image
$name
$location
$number
$email

EMAIL;

$message = '$model,
$year,
$info,
$image,
$name,
$location,
$number,
$email';

if($_POST){
    mail($to, $subject, $message, $header);
    $feedback = 'Thanks, your quote is one its way.';
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.