PHPMailer发送带有数组的电子邮件

时间:2014-04-25 12:21:28

标签: php html-email

您好我对HTML表单数组和PHP有疑问。例如,我有姓名和电子邮件,但要求6次,我想发送此邮件。我应该编辑什么才能工作?谢谢!

HTML:

   <form  method="Post" action="send.php" onSubmit="return validate();">
    <?php
     $amount=6; //amount shows the number of data I want to repeat
     for( $i = 0; $i < $amount; $i++ ) {
        ?>
        <b>Data <?php echo $i+1 ?>º</b>
          <input type="edit" name="Name[]" size="40">
          <input type="edit" name="email[]" size="40">
          <br>
    <?php } ?>
          <input type="submit" name="Submit" value="send 6 data mail">
   </form>

send.php:

<?php
       require('phpmailer/class.phpmailer.php');
       $name= $_POST['name[]']; 
       $email= $_POST['email[]']; 
       $mail = new PHPMailer();
       ...
       $mail->Body = ' Data<br> '
    <?php
     $amount=6; //amount shows the number of data I want to repeat
     for( $i = 0; $i < $amount; $i++ ) {
        ?> '
       name: '.$name[$i].' email: '.$email[$i];
       ...
       $mail->Send();
?>

应发送:

Data
name: nameinput1 email: emailinput1
name: nameinput2 email: emailinput2
name: nameinput3 email: emailinput3
name: nameinput4 email: emailinput4
name: nameinput5 email: emailinput5
name: nameinput6 email: emailinput6

2 个答案:

答案 0 :(得分:0)

您可以使用以下内容;

 <?php
    require('phpmailer/class.phpmailer.php');
    $name= $_POST['name']; 
    $email= $_POST['email'];

    $mail = new PHPMailer();
    ...
    $mail->Body = ' Data<br> ';
    $amount=count($name); //amount shows the number of data I want to repeat
    for( $i = 0; $i < $amount; $i++ ) {
        $mail->Body .= 'name: '.$name[$i].' email: '.$email[$i];
    } 
    ...
    $mail->Send();
?>

答案 1 :(得分:0)

您可以尝试以下内容:

$mail->Body = ' Data<br> ';
 $amount=6; //amount shows the number of data I want to repeat
 for( $i = 0; $i < $amount; $i++ ) {
   $mail->Body .= 'name: '.$name[$i].' email: '.$email[$i]."<br>";
 }
   ...
$mail->Send();
?>