Hey Guys,
I’ve tried everything, but anytime use an apostrophe in our subject or message, php adds a \. How can I remove it? Here is the code:
<?php
$subject = $_POST['subject'];
$message = $_POST['message'];
$email_list = $_POST['emailsaddresses'];
$emails = explode(",",$email_list);
if ($email_list=="") {
echo "No Email Addresses Provided!";
}
else
{
foreach($emails as $email)
{
echo 'Now sending a message to '.$email.'<br />';
if(!mail("$email", "$subject", "$message", "From: me@me.com", "-fme@me.com"))
{
echo 'Error when sending to '.$email.'<br />';
}
}
}
?>
Also, is there a limitation on how emails we can send before it times out? We have about 250-300 emails to send a month (these are paid subscribers). Is there a way to prevent it from timing out?
Any help is greately appreciated!
stripslashes() will strip the slashes…
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
to avoid time out use set_time_limit(0) at the top of the script
allow me to do some code optimizations:
<?php
set_time_limit(0);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$email_list = $_POST['emailsaddresses'];
$emails = explode(',',$email_list);
if (empty($email_list))
echo 'No Email Addresses Provided!';
else
{
foreach($emails as $email)
{
echo 'Now sending a message to ', $email, '<br />';
if(!mail($email, $subject, $message, 'From: me@me.com', '-fme@me.com'))
{
echo 'Error when sending to ', $email, '<br />';
}
}
}
?>
1. to remove slashes use stripslashes() or str_replace(‘\\’,‘’,$string)
2. the timeout is because of your script execution timing out, add set_time_limit() within the loop before making a call to teh mail() func
stripslashes! Ahh dang!
Thanks so much. Works like a charm!