Page 1 of 1
using the mail() function
Posted: Mon Jul 16, 2007 3:18 pm
by paladaxar
I'm trying to send some emails using the mail() function. I am using a textarea to input the text to send, then sending it through a session to the page that actually does the emailing.
When the email is sent, everywhere that I used one return (press enter), it places two. Everywhere there is 2, it puts 4. Is there any way to avoid this? When I type the body of the email, I want it to send like I see it. No extra lines.
Posted: Mon Jul 16, 2007 3:20 pm
by hawleyjr
Can we see your code?
Posted: Mon Jul 16, 2007 3:29 pm
by paladaxar
emailer.php
Code: Select all
<?php
session_start();
if ( $submit_form )
{
session_register('subject', 'body', 'email_addresses');
$subject = $_POST['subject'];
$body = $_POST['body'];
$email_addresses = $_POST['email_addresses'];
header("location: process_emailer.php");
}
?>
Sent Emails:
<?php
echo "$sent_to";
?>
<table border = '1'>
<form action="emailer.php" method="post">
<tr>
<td>Email:</td>
<td></td>
</tr>
<tr>
<td>Subject:</td><td><input type = 'text' name = 'subject' /></td>
</tr>
<tr>
<td>Body:</td> <td><textarea rows = '20' cols = '50' name = 'body'></textarea></td>
</tr>
<tr>
<td colspan="2">
Enter email addresses, one on each line
</td>
</tr>
<tr>
<td colspan="2">
<textarea rows="20" cols="50" name="email_addresses"></textarea>
</td>
</tr>
<tr>
<td colspan="2">
<input type = 'submit' name = 'submit_form' value = "send emails" />
</td>
</tr>
</form>
</table>
process_emailer.php
Code: Select all
<?php
session_start();
session_register('sent_to');
$sent_to = "<br>";
include("lidb.php");
$email_array = explode("\n", $email_addresses);
$body = stripslashes($body);
$subject = stripslashes($subject);
foreach ( $email_array as $email )
{
mail($email, $subject, $body, "From: Sub-List-Online");
$date = date("Y-m-d", time());
$query = "insert into emailed (email_address, a) values ('$email', '$date')";
$result = mysql_query($query);
$sent_to = $sent_to."Sent: $email"."<br>";
}
header("location: emailer.php");
?>
Posted: Mon Jul 16, 2007 10:52 pm
by feyd
Your code appears to assume register_globals is on. It's also using the long deprecated session_register().
Header() based redirection should always use a full URL, http:// and all.
I would strongly suggest you use Swiftmailer.