Jump to content

How to add attachments with mail() ?


ankur0101

Recommended Posts

Hi

I am creating a simple program to send e-mail.

 

 

It contains 2 pages, index.php and sendmail.php

 

 

Here is the code of index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Send Mail #1</title>
</head>


<body>
<p> </p>
<p>    Mail 1</p>
<form id="form1" name="form1" method="post" action="sendmail.php">
  <table width="821" height="240" border="0">
    <tr>
      <td width="168">To :</td>
      <td colspan="2"><label>
        <input name="to_textbox" type="text" id="to_textbox" size="75" />
      </label></td>
    </tr>
    <tr>
      <td>Subject :</td>
      <td colspan="2"><label>
        <input name="subject_textbox" type="text" id="subject_textbox" value="" size="75" />
      </label></td>
    </tr>
    <tr>
      <td>From :</td>
      <td colspan="2"><label>
        <input name="from_textbox" type="text" id="from_textbox" value="" size="75" />
      </label></td>
    </tr>
    <tr>
      <td>Content :</td>
      <td colspan="2"><label>
        <textarea name="content_textbox" id="content_textbox" cols="75" rows="5">





               </textarea>
      </label></td>
    </tr>
    <tr>
      <td> </td>
      <td width="153"><label>
        <input type="submit" name="send_button" id="send_button" value="Send..." />
      </label></td>
      <td width="486"><label>
        <input type="reset" name="reset_button" id="button" value="Reset" />
      </label></td>
    </tr>
  </table>
  <p> </p>
  <p> </p>
  <p> </p>
</form>
<p> </p>
</body>
</html>

 

 

Code for sendmail.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>


<body>
<?php


$to = $_POST["to_textbox"];
$from = $_POST["from_textbox"];
$subject = $_POST["subject_textbox"];
$message = $_POST["content_textbox"];
$headers = "From: " . $from . "\r\n";
$mailsent = mail($to, $subject, $message, $headers);
if ($mailsent) {
echo " <center> Congrats ! The message has been sent </center>";
echo " <center><b>\n To: $to </b></center>";




}
else
{
echo " There was an error...";
}




?>
</body>
</html>

 

 

How can I add attachments ? I want to add few photos (.jpg)

I searched on google but found nothing which can relate with mail()

Link to comment
Share on other sites

  • 6 months later...
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.