PHP表单带有多个附件“ foreach”

时间:2018-08-09 10:33:32

标签: php arrays foreach phpmailer email-attachments

$mail_to_send = new PHPMailer();

$mail_to_send->FromName = $author;
$mail_to_send->From     = $email;
$mail_to_send->Subject  = $subject;
$mail_to_send->Body     = "Mittente: ". $author . "\n" . "\n" . "Contatto di 
riferimento: " . $contatto . "\n" . "\n" . "Tipo di annuncio: " . $tipo . 
"\n" . "\n". $message;

$mail_to_send->AddReplyTo($email);
//contact form destination e-mail:
$mail_to_send->AddAddress('mymail@gmail.com'); 
foreach ($_FILES['attachment'] as $_allegato){

if ( !$_allegato['attachment']['error'] == 4 ) { //something was send


    if ( $_allegato['attachment']['error'] == 0 && 
    is_uploaded_file($_allegato['attachment']['tmp_name']) )


        $mail_to_send->AddAttachment($_allegato['attachment']['tmp_name'], 
        $_allegato['attachment']['name']);

    else 

    wp_die('Error: there was a problem with the file upload. Try again 
    later.');
    }   
   }

为什么我的foreach不起作用? foreach ($_FILES['attachment'] as $_allegato){

我需要使用$ mail_to_send发送多个附件,但是我对php $ files不熟悉。

谢谢。

0 个答案:

没有答案
相关问题