2

I'm using PHPMailer to mail form data in an HTML form when the user submits the form. The syntax error comes when putting quotes around fullName in the body of the email. If there are no quotes, it doesn't show an error. I'm new to PHP and am not really sure how to reference an HTML form from within PHP, when I've declared that a set of code is HTML. Here is my code:

NOTE: I'm using Dreamweaver to code this and sometimes the syntax correction is incorrect, but I want to make sure before I go ignoring it and code my entire document.

<?php
require("class.phpmailer.php");
$mail = new PHPMailer();$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->SMTPAuth = true;
$mail->Username = 'smtpusername';
$mail->Password = 'smtppassword';

$mail->From="[email protected]";
$mail->FromName="My site's mailer";
$mail->Sender="[email protected]";

$mail->AddAddress("[email protected]");
$mail->Subject = "Test 1";

$mail->IsHTML(true);
$mail->Body = "
<h1>Graphics Request</h1>

Name: $_POST['fullName']<br />
";
$mail->AltBody="This is text only alternative body.";

if(!$mail->Send())
{
   echo "Error sending: " . $mail->ErrorInfo;;
}
else
{
   echo "Letter is sent";
}
?>
1
  • Enclose in {} inside the double-quoted string as in {$_POST['fullName']} Commented Jun 28, 2012 at 19:56

3 Answers 3

1

That is, in fact, a syntax error in PHP. Because you're inside a double-quoted string, you can (and must) just write $_POST[fullname] there.

This is an example of the designers of PHP trying to help you. Like they did when they broke the boolean operators and the behavior of continue inside a switch.

Sign up to request clarification or add additional context in comments.

3 Comments

Or use something like {$variable}
@Napolux: Or that. I tend to go for the concise option.
Gotcha. Thanks! Looks like I'm going to have an interesting time learning PHP.
1

I put all post results in variables, you should get into this habit, it makes thing like the above work . Just my .02 cents

Comments

0

Rewrite as:

$mail->Body = "
<h1>Graphics Request</h1>

Name: {$_POST['fullName']}<br />
";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.