0

On my site I hava two forms witch send email. The one whit no attachment needed is sent correnctly, but the other ony witch has an attachment does not get sent. I am using SMTP config whit Postman SMTP plugin.

move_uploaded_file($_FILES["cv"]["tmp_name"],WP_CONTENT_DIR .'/uploads/CV/'.basename($_FILES['cv']['name']));
move_uploaded_file($_FILES["lm"]["tmp_name"],WP_CONTENT_DIR .'/uploads/lm/'.basename($_FILES['lm']['name']));

$attachments = array(
    WP_CONTENT_DIR ."/uploads/CV/".$_FILES["cv"]["name"],
    WP_CONTENT_DIR ."/uploads/lm/".$_FILES["lm"]["name"]
    );

this is the code I use for storeing and reaching the attachments and simpli useing the wp_mail function to send it like this:

$sent=wp_mail($s, $subject, $message, $headers,$attachments);

On the other form I am useing the same code just whitout the $attachments variable. The one whitout attachements get sent but the other one does not. Can anyone help me finx my problem?

0

Try code below.

<?php
$attachments = array();

array_push($attachments, WP_CONTENT_DIR . '/uploads/my-first-attachment.docx' );
array_push($attachments, WP_CONTENT_DIR . '/uploads/my-second-attachment.zip' );

$to="my-friend@some-doamin.info";
$subject="Online: multiple attachment demo through wp_mail of wordpress";
$message="This is testing";
$headers = 'From: NAPSWI online <online@napswi.org>';
get_header();
if( wp_mail( $to, $subject, $message, $headers, $attachments) ) {
 // the message was sent...
 echo 'The test message was sent. Check your email inbox.';
} else {
 // the message was not sent...
 echo 'The message was not sent!';
}
?>
| improve this answer | |
  • Unfortunately does not work :( the mail doesn't get sent – StoneSmith Oct 13 '16 at 10:56
0

i would also try adding to the array using the fashion below. (see my example) try using the actual location of the 2 files as just a test then insert the php. I've outlined 3 different options to try out, but of course you should use the actual url on your site to those files/

<?php
$attachments = array(); //may or may not be needed.

$att1 = WP_CONTENT_DIR . '/uploads/my-1st-attachemnt.zip';
$att2 = WP_CONTENT_DIR . '/uploads/my-second-attachment.zip';


$attachments[] =$att1; //try these as working solution
$attachments[] =$att2; //try these as working solution 


$attachments[] = 'http://www.example.com/wp-content/uploads/my-1st-attachemnt.zip';  //try this 2nd
$attachments[] = '/wp-content/uploads/my-second-attachment.zip';  //try this last


$to="my-friend@some-doamin.info";
$subject="Online: multiple attachment demo through wp_mail of wordpress";
$message="This is testing";
$headers = 'From: NAPSWI online <online@napswi.org>';
get_header();
if( wp_mail( $to, $subject, $message, $headers, $attachments) ) {
 // the message was sent...
 echo 'The test message was sent. Check your email inbox.';
} else {
 // the message was not sent...
 echo 'The message was not sent!';
}
?>
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.