Jump to content

Sending 1 e-mail having attachment with SMTP


ankur0101

Recommended Posts

Hi,

I am looking for a script which will help me to send prebuilt e-mail to people with attachments.

Something like this >>>

 

To : [ ________________                                              ]  <--Textbox

Subject : [                        _____________] <-- Subject

Main body :

[___________________]

[___________________]

[___________________]

[___________________]

[___________________]      <-- with html

 

[ Submit ]

 

I would like to attach 5 photos in .jpg which are hosted on server.

 

Now everything is prebuilt except "To : " as peoples email ID will always change. When Submit is clicked, main body Data and attachment will be sent to "To :" person with SMTP and not php mail()

 

Well I have covered till sending mail with SMTP, using PEAR PHP, but I am not able to send attachments i.e. photos.

 

I have 2 pages, index.php - 1st page which includes form and button

sendmail.php - Includes all function and main data

Following is the code of sendmail.php

<?php

include("Mail.php");

include('Mail/mime.php');

 

$to = $_POST["to_textbox"];

$from = $_POST["from_textbox"];

$subject = $_POST["subject_textbox"];

$message = $_POST["content_textbox"];

$headers = "From: " . $from . "\r\n";

 

/* SMTP server name, port, user/passwd */

$smtpinfo["host"] = "xbc.pqr.com";

$smtpinfo["port"] = "465";

$smtpinfo["auth"] = true;

$smtpinfo["username"] = "user";

$smtpinfo["password"] = "pass";

/////////////////Attachments Section Start //////////////

$file = '/home/xyzuser/public_html/xbx.pqr.com/mail1/img/linux_logo.jpg';

$crlf = "\n";

$mime = new Mail_mime($crlf);

$mime->addAttachment($file, 'image/jpeg');

//do not ever try to call these lines in reverse order

$attach= $mime->get();

///////////////Attachment Section ends ////////////////

 

/* Create the mail object using the Mail::factory method */

$mail_object =& Mail::factory("smtp", $smtpinfo);

/* Ok send mail */

$mail_object->send($to, $headers, $subject, $message, $attach);

 

?>

Now problem is, it is not sending linux tux logo from "img" folder i.e. mail sent with just text from previous page's textbox. It is not handling with attachment i.e. photo, what to do ?

 

Thanks to http://pear.php.net/manual/en/packag...me.example.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.