Jump to content

mail()


dudejma

Recommended Posts

I'm trying to send mail with an attachment and it doesn't even try to send it. I'm not very experienced with mail or attachments, this is the first script with attachments I have every used. I'm not sure if I did it all right or not because I read a tutorial on it. Here's the code:

 

if (isset($_POST['submit'])) {
$getPilots = "SELECT * FROM users WHERE emailOption = '1' AND status = '1'";
$runGetPilots = mysql_query($getPilots);
$emails_arr = array();
$info = mysql_fetch_array($runGetPilots);
$emails_arr[] = $info['email'];
$to = implode(', ', $emails_arr);
$subject = $_POST['subject'];
$message = stripslashes($_POST['message']);
$fileName = $_POST['newsletter'];
$fileType = substr($fileName, strlen($fileName)-4, strlen($fileName));
$contents = chunk_split(base64_encode(file_get_contents("../newsletter/$fileName")));
$uid = md5(uniqid(time()));
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: Virtual American <[email protected]>\r\n";
$headers .= "Reply-To: Virtual American <[email protected]>\r\n";
$headers .= "Return-Path: Virtual American <[email protected]>\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "This is a multi-part message in MIME format.\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $message."\r\n\r\n";
$headers .= "--".$uid."\r\n";
$headers .= "Content-Type: ".$fileType."; name=\"".$fileName."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$fileName."\"\r\n\r\n";
$headers .= $contents."\r\n\r\n";

if (!mail($to,$subject,"",$headers)) {

$errors .= "There was an error sending the email(s). Please contact the webmaster. <br />";
error_log("The mail didn't work!",0);
} else {

header("Location: ac.php?message=1");

}

} else {}

 

I'm sure there is more to include, but I'm not exactly sure what, maybe the form?

 

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
					<table border="0" cellpadding="6" cellspacing="6">
					<tr>
					<td><b>Subject: </b></td>
					<td><input type="text" name="subject" value="<?php echo $_POST['subject']; ?>" size="24" maxlength="70" /></td>
					</tr>
					<tr>
					<td><b>Message: </b></td>
					<td><textarea cols="40" rows="20" name="message"><?php echo $_POST['message']; ?></textarea></td>
					</tr>
					<tr>
					<td><b>Newsletter: </b></td>
					<td><select name="newsletter">
					<?php
					$handle = opendir("../newsletter");
					while (false !== ($entry = readdir($handle))) {
					if ($_POST['newsletter'] == $entry) {
					$selected = 'selected="selected"';
					} else {
					$selected = "";
					}
					if ($entry != "." && $entry != "..") {
        				echo '<option value="' . $entry . '" $selected>' . $entry . '</option>';
					}
					}
					echo '</select>';
					?>

Link to comment
https://forums.phpfreaks.com/topic/255550-mail/
Share on other sites

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.