Скрипт Php Email - PullRequest
       1

Скрипт Php Email

0 голосов
/ 09 ноября 2011

Ниже приведен мой php-скрипт: у меня есть страница, где клиент заполняет форму, и данные обрабатываются этой формой и отправляют мне данные в хороших таблицах по электронной почте. однако вместо данных отображаются переменные. (т. е. $ name)

Пожалуйста, помогите.

<?php

$fullname=$_POST['fullname'];
$companyname=$_POST['companyname'];
$idnumber=$_POST['idnumber'];
$dob=$_POST['dob'];
$addressone=$_POST['addressone'];
$addresstwo=$_POST['addresstwo'];
$postalcode=$_POST['postalcode'];
$citystate=$_POST['citystate'];
$country=$_POST['country'];
$mobile=$_POST['mobile'];
$homework=$_POST['homework'];
$email=$_POST['email'];
$altemail=$_POST['altemail'];
$dob=$_POST['dob'];
$tc=$_POST['tc'];
$username=$_POST['username'];
$password=$_POST['password'];

//define the receiver of the email
$to = 'test@test.com';
//define the subject of the email
$subject = 'Test HTML email'; 
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash
$random_hash = md5(date('r', time())); 
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: test@test.com\r\nReply-To: test@test.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; 
//define the body of the message.
ob_start(); //Turn on output buffering
?>
--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<span style="font-family: Arial; font-size:16pt; color: #595959;"><strong>New Account Registration</strong></span><p>&nbsp;</p>

<span style="font-family: Arial; font-size:12pt; color: #595959;"> $fullname has filled in the following information:<p>
</span>


<table cellspacing"2" border="0" "cellpadding="5px" style="font-family: Arial; font-size: 11pt; color: #777777;">


<tr>  <!-- Full Name -->
     <td>* Full Name:</td>
     <td><?php echo '$fullname'; ?></td>
</tr>


<tr>  <!-- Company Name -->
     <td>* Company Name:</td>
     <td>$companyname</td>
</tr>

<tr>  <!-- ID Number / Passport Number -->
     <td>* ID Number / Passport No.</td>
     <td>$idnumber</td>
</tr>

<tr>  <!-- Date of Birth -->
     <td>* Date of Birth</td>
     <td>$dob</td>
</tr>

<tr><td><strong>&nbsp;</strong></td></tr>
<tr>  <!-- Address Line 1 -->
     <td>* Address Line 1</td>
     <td>$addressone</td>
</tr>
<tr>  <!-- Address Line 2 -->
     <td>* Address Line 2</td>
     <td>$addresstwo</td>
</tr>
<tr>  <!-- Postal Code  -->
     <td>* Postal Code</td>
     <td>$postalcode</td>
</tr>

<tr>  <!-- City / State  -->
     <td>* City / State</td>
     <td>$citystate</td>
</tr>

<tr>  <!-- Country  -->
     <td>* Country</td>
     <td>$country</td>
</tr>

<tr><td><strong>&nbsp;</strong></td></tr>

<tr>  <!-- Mobile Number  -->
     <td>* Mobile Number</td>
     <td>$mobile</td>
</tr>

<tr>  <!-- Home / Work  -->
     <td>* Home / Work No.</td>
     <td>$homework</td>
</tr>

<tr>  <!-- Email Address  -->
     <td>* Email Address:</td>
     <td>$email</td>
</tr>

<tr>  <!-- Alternate Address  -->
     <td>* Alternate Address:</td>
     <td>$altemail</td>
</tr>
<tr><td><strong>&nbsp;</strong></td></tr>
<tr>  <!-- Username -->
     <td>* Username:</td>
     <td>$username</td>
</tr>
<tr>  <!-- Password -->
     <td>* Password:</td>
     <td>$password</td>
</tr>
<tr>  <!-- Terms and Conditions -->
     <td colspan="2">$tc Agreed to the <a href="http://www.test.html">Terms & Conditions</a>.</td>
     <td></td>
</tr>
</table>
--PHP-alt-<?php echo $random_hash; ?>--
<?
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed";
?>

Ответы [ 3 ]

2 голосов
/ 09 ноября 2011

Вы пропускаете <?php echo $variable ?> везде. PHP-код выполняется только в том случае, если он содержится в <?php ?> пар скобок. В противном случае это просто «текст» и напрямую выводится. Ни одна из переменных в вашей форме не обрабатывается как код PHP, следовательно, выводится как текст, а не как их содержимое.

0 голосов
/ 09 ноября 2011

Один пример для всех:

<span style="font-family: Arial; font-size:12pt; color: #595959;"> $fullname has filled in the following information:<p>

Это неправильно.

Переменные должны быть напечатаны (с помощью функции echo или print в PHP-скрипте на стороне сервера).

Но если настройки php на вашем веб-сервере позволяют это, вы можете использовать краткую форму <? = $ Fullname?> Вместо $ fullname, которая является синтаксическим сахаром без ввода функции echo / print.

0 голосов
/ 09 ноября 2011

Может быть для каждого var сделать это:

<?php echo $varname; ?>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...