Here i have a code like getting the data from index.php , if user enter the data it will show like table and as well as it should go to email to some predefined mail. But here i am getting data Dynamically , i tried with $_REQUEST and $_POST both methods to get the data , but in mail function i am trying to change message parameter but by php tags its is not taking and showing some syntax errors.
please go through code here
<?php
$to="[email protected]";
$fn="Fisrt Name";
$ln="Last Name";
$name=$fn.' '.$ln;
$from="[email protected]";
$subject = "Wele to Website";
include('newsmtp/smtpwork.php');
?>
<?php
$message = 'Dear $firstName,
Your Wele Message.'.'
<table border=1>
<tr>
<td>First Name:</td>
<td><?php $firstName=$_POST['firstname'];
echo $firstName;?></td>
</tr>
<tr>
<td>Last Name:</td>
<td><?php $lastname=$_POST['lastname'];
echo $lastname;?></td>
</tr>
<tr>
<td>Title:</td>
<td><?php $title=$_POST['title'];
echo $title;?></td>
</tr>
<tr>
<td>Address:</td>
<td><?php $address=$_POST['address'];
echo $address;?></td>
</tr>
<tr>
<td>Phone Number:</td>
<td><?php $phone=$_POST['phone'];
echo $phone;?></td>
</tr>
<tr>
<td>Course Name:</td>
<td><?php $course=$_POST['coursename'];
echo $course;?></td>
</tr>
<tr>
<td>Website:</td>
<td><?php $website=$_POST['website'];
echo $website;?></td>
</tr>
</table>
Thanks
xxxxxxxxxxxx
';
?>
Here i have a code like getting the data from index.php , if user enter the data it will show like table and as well as it should go to email to some predefined mail. But here i am getting data Dynamically , i tried with $_REQUEST and $_POST both methods to get the data , but in mail function i am trying to change message parameter but by php tags its is not taking and showing some syntax errors.
please go through code here
<?php
$to="[email protected]";
$fn="Fisrt Name";
$ln="Last Name";
$name=$fn.' '.$ln;
$from="[email protected]";
$subject = "Wele to Website";
include('newsmtp/smtpwork.php');
?>
<?php
$message = 'Dear $firstName,
Your Wele Message.'.'
<table border=1>
<tr>
<td>First Name:</td>
<td><?php $firstName=$_POST['firstname'];
echo $firstName;?></td>
</tr>
<tr>
<td>Last Name:</td>
<td><?php $lastname=$_POST['lastname'];
echo $lastname;?></td>
</tr>
<tr>
<td>Title:</td>
<td><?php $title=$_POST['title'];
echo $title;?></td>
</tr>
<tr>
<td>Address:</td>
<td><?php $address=$_POST['address'];
echo $address;?></td>
</tr>
<tr>
<td>Phone Number:</td>
<td><?php $phone=$_POST['phone'];
echo $phone;?></td>
</tr>
<tr>
<td>Course Name:</td>
<td><?php $course=$_POST['coursename'];
echo $course;?></td>
</tr>
<tr>
<td>Website:</td>
<td><?php $website=$_POST['website'];
echo $website;?></td>
</tr>
</table>
Thanks
xxxxxxxxxxxx
';
?>
Share
Improve this question
asked Feb 5, 2013 at 11:33
user1696874user1696874
131 silver badge4 bronze badges
1
- Use phpMailer. Instructions available on the site. – SDC Commented Feb 5, 2013 at 11:36
3 Answers
Reset to default 2Try this method, assign the posted values in variables, outside the $message variable and print the variable inside your $message variable
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$title = $_POST['title'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$course = $_POST['course'];
$website = $_POST['website'];
$message = 'Dear '.$firstName.',
Your Wele Message.'.'
<table border=1>
<tr>
<td>First Name:</td>
<td>'.$firstname.' </td>
</tr>
<tr>
<td>Last Name:</td>
<td>'.$lastname.'</td>
</tr>
<tr>
<td>Title:</td>
<td>'.$title.'</td>
</tr>
<tr>
<td>Address:</td>
<td>'.$address.'</td>
</tr>
<tr>
<td>Phone Number:</td>
<td>'.$phone.'</td>
</tr>
<tr>
<td>Course Name:</td>
<td>'.$course.'</td>
</tr>
<tr>
<td>Website:</td>
<td>'.$website.'</td>
</tr>
</table>
Thanks
xxxxxxxxxxxx
';
?>
$to ="[email protected]";
$subject = "Wele to Website";
$headers = 'From: xxxxxx <[email protected]>' . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\r\n";
$sent = @mail($to,$subject,$message,$headers);
if ($sent) {
return true;
} else {
return false;
}
Also add necessary header to send HTML mail as Vinoth Babu, Naveen suggested
$to = "[email protected]";
$subject = $name ." is contact ";
$headers = "MIME-Version: 1.0" . "\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\n";
@mail($to,$subject,$message,$headers);
set headers to mime version & type of your message like text/html
To send HTML Content/Tables you have to add the following in the header of that mail,
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail($to, $subject, $message, $headers);
please refer the link below,
Mail Function
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745315828a4622214.html
评论列表(0条)