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
https://forums.phpfreaks.com/topic/201145-how-to-add-attachments-with-mail/
Share on other sites

  • 6 months later...

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.