helios
helios

Reputation: 13

Unable to add attachment(s) to Mail API in server from localhost

The below code resides in our server. I want to attach file(s) from my local machine without uploading that to server. How can I do this?

$local_file_name = array('Wall.jpg'); //$_FILES['attachment']['name'];
$local_file_path = array('C:\Users\abc\Downloads\Attachment\Wall.jpg'); //$_FILES['attachment']['tmp_name'];
$size = sizeof($local_file_name);
for ($j = 0; $j < $size; $j++) {
    $mail->addStringAttachment(file_get_contents($local_file_path[$j]), $local_file_name[$j]);
}

Upvotes: 0

Views: 101

Answers (2)

Synchro
Synchro

Reputation: 37730

You can’t do this. Either upload the file (easy), allow your server to connect to your local machine and access files on it (much harder), host files somewhere else and provide remote access to them.

Upvotes: 1

xMayank
xMayank

Reputation: 1995

Sample code to add the attachment to phpMailer

$mail->addAttachment('<folder>/image.jpg', 'new.jpg');

Upvotes: 1

Related Questions