using the mail() function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paladaxar
Forum Commoner
Posts: 85
Joined: Fri Jun 18, 2004 11:50 pm

using the mail() function

Post 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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Can we see your code?
paladaxar
Forum Commoner
Posts: 85
Joined: Fri Jun 18, 2004 11:50 pm

Post 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");
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply