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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.