Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Sending to more than one email address

the mail() function

Moderators: macek, egami, gesf

Sending to more than one email address

Postby doug145 » Sun Dec 25, 2011 4:29 pm

I have a form on a web page and it sends an email to the person filling it out when they click on the Submit button. I am trying add a second email address to the mail function so the second email address will receive a copy of the same email. Can someone please tell me how to send the email to more than one address without getting an error?
The code I am using for just one email address is below.

Doug

<?php
$error_message = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
$action = isset($_POST['action']) ? $_POST['action'] : '';
$database = './apexprof_777yyy_db.php';
$success_page = 'signup_confirm.php';

if (!file_exists($database))
{
echo 'User database not found!';
exit;
}
if ($action == 'signup')
{
$newusername = $_POST['username'];
$newemail = $_POST['email'];
$newpassword = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$newfullname = $_POST['fullname'];
if ($newpassword != $confirmpassword)
{
$error_message = 'Password and Confirm Password are not the same!';
}
else
if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newusername))
{
$error_message = 'Username is not valid, please check and try again!';
}
else
if (!ereg("^[A-Za-z0-9_!@$]{1,50}$", $newpassword))
{
$error_message = 'Password is not valid, please check and try again!';
}
else
if (!ereg("^[A-Za-z0-9_!@$.' &]{1,50}$", $newfullname))
{
$error_message = 'Fullname is not valid, please check and try again!';
}
else
if (!ereg("^.+@.+\..+$", $newemail))
{
$error_message = 'Email is not a valid email address. Please check and try again.';
}
$items = file($database);
foreach($items as $line)
{
list($username, $password, $email, $fullname) = explode('|', trim($line));
if ($newusername == $username)
{
$error_message = 'Username already used. Please select another username.';
break;
}
}
if (empty($error_message))
{
$file = fopen($database, 'a');
fwrite($file, $newusername);
fwrite($file, '|');
fwrite($file, md5($newpassword));
fwrite($file, '|');
fwrite($file, $newemail);
fwrite($file, '|');
fwrite($file, $newfullname);
fwrite($file, '|1');
fwrite($file, "\r\n");
fclose($file);

$mailto = $newemail;
$subject = 'Your new account at our program';
$message = 'A new account has been setup at our program. We look forward to serving your investment needs.';
$message .= "\r\nUsername: ";
$message .= $newusername;
$message .= "\r\nPassword: ";
$message .= $newpassword;
$message .= "\r\n";
$header = "From: trafagar.walsh@yahoo.com"."\r\n";
$header .= "Reply-To: trafagar.walsh@yahoo.com"."\r\n";
$header .= "MIME-Version: 1.0"."\r\n";
$header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
$header .= "Content-Transfer-Encoding: 8bit"."\r\n";
$header .= "X-Mailer: PHP v".phpversion();
mail($mailto, $subject, $message, $header);
header('Location: '.$success_page);
exit;
}
}
}
?>
Last edited by doug145 on Tue Dec 27, 2011 9:18 am, edited 1 time in total.
doug145
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Dec 25, 2011 4:24 pm

Re: Sending to more than one email address

Postby doug145 » Tue Dec 27, 2011 9:12 am

Anyone at all, please help me on my question.
doug145
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sun Dec 25, 2011 4:24 pm


Return to PHP coding => Mail

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron