2012-06-22 12 views
14

तो बिना यह कर:PHPMailer लगाव, एक भौतिक फ़ाइल

// Setup mail class, recipients and body 
$mailer->AddAttachment('/home/mywebsite/public_html/file.zip', 'file.zip'); 
The AddAttachment function has four arguments: 

AddAttachment(PATH_TO_FILE, FILENAME, ENCODING, HEADER_TYPE) 

मैं xmail() का उपयोग करते थे और जब मैं एक लगाव यहां कहा, मैं फ़ाइल नाम और सामग्री है कि यह होना चाहिए पारित कर दिया।

इस तरह

:

$xmail->addAttachment('myamazingfile.pdf', $content); 

मैं इसे उसी तरह काम करते हैं, इसलिए जब मैं PHPMailer वर्ग से AddAttachment() कहते हैं, मैं या तो एक ही है या यह की तरह कुछ पारित कर सकते हैं कर सकते हैं कैसे, तो मैं करने की जरूरत है न मेरे सर्वर पर भेजने के लिए एक वास्तविक फाइल है?

उत्तर

29
AddStringAttachment($string,$filename,$encoding,$type) 

जैसे

$mail = new PHPMailer(); 
$mail->AddStringAttachment($string,$filename,$encoding,$type); 

http://phpmailer.worxware.com/index.php?pg=tutorial#3

+1

बहुत अच्छा। आपके उत्तर के लिए धन्यवाद – Karem

+0

किसी भी व्यक्ति को यह कोशिश करने के लिए, एन्कोडिंग "बेस 64" होगी और $ प्रकार एमआईएमई प्रकार की एक स्ट्रिंग है। – daviddukeuk

+0

इस पल में लिंक टूट गया है –

1

के बाद से है कि AddAttachment() फ़ंक्शन बाइट डाटा की तुलना में एक पथ उम्मीद कर रही है बल्कि, आप एक php अस्थायी फ़ाइल समारोह में बदलने और फिर अपने समारोह में उस पथ स्ट्रिंग पारित करना चाहिए

$prefix  = 'ConvertMediaArgs_'.time().'_'; 
$tempfile = tempnam($this->tempdir, $prefix); 

// Args file create failure: kill script with TEMPFILEFAIL error 
if($tempfile === false) { 
    die('file could not be created'); 
} 

// Write args as Key=Val (\n) to file 
$fullpath = $this->tempdir.$tempfile; 
$content = $someContent // <---------------- this is your file's data 
$handle  = fopen($tempfile, "w"); 
fwrite($handle, $content); 

// $fullpath is the path you wanna pass to your function 
$xmail->addAttachment($fullpath, $content); 
+0

आपके प्रयास के लिए धन्यवाद +1 – Karem

+0

@karem कोई समस्या नहीं – Kristian

संबंधित मुद्दे