Jump to content

PHP Email $row From Mysql


bbizzl

Recommended Posts

Hello!

 

Currently I have a form where the user can submit emails in a comma separated format to the $row in database $contacts. How can I set this up correctly so the user can email their contacts? As of right now the script emails everybody but just not in the correct email format. Thank You! The problem is when the emails are sent out; multiple email addresses are in the "to field" of the recipients email.  Example if there are 5 email addresses saved in the user row $contacts; 5 email addresses show in each of the  recipients to field of their email.

 

The problem is when the emails are sent out; multiple email addresses are in the "to field" of the recipients email. Example if there are 5 email addresses saved in the user row $contacts; 5 email addresses show in each of the recipients to field of their email.

 

<?php
$formMessage = "";
$senderName = "";
$senderEmail = "";
$senderMessage = "";
if (isset($_POST['cusername']))
{


    $senderName = $_POST['cusername'];
    $senderEmail = $_POST['cemail'];
    $senderMessage = $_POST['msg'];
    if (!$senderName || !$senderEmail ) {

         $formMessage = "The form is incomplete, please fill in all fields.";

    } else {  

        $senderName = strip_tags($senderName);
        $senderName = stripslashes($senderName);
        $senderEmail = strip_tags($senderEmail);
        $senderEmail = stripslashes($senderEmail);
        $senderMessage = strip_tags($senderMessage);
        $senderMessage = stripslashes($senderMessage);

$to = $contacts;
        

   $from = "";
        $subject = "Prospect For Property";
    
      $message = '<html><body>';


$message .= "</body></html>";
         $headers = "MIME-Version: 1.0\r\n";

      
       

$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        mail($to, $subject, $message, $headers);
        $formMessage = "Thanks, your message has been sent.";
        $senderName = "";
        $senderEmail = "";
        $senderMessage = "";
    } 

} 
?> 

 

MOD EDIT: PHP Manual link [m] . . . [/m] tags changed to

 . . . 

tags . . .

Link to comment
Share on other sites

  • 2 months later...

Hi,

 

is $contacts an array ?

 

if its not explode it. for example

 

$strContacts = "name@domain.com, name@domain.com, name@domain.com";

$arrContacts = explode(", " $strContacts);

 

Then once all of your contacts are in an array loop round them sending the emails

 

 


$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        
        
foreach ($arrContacts as $strContact)
{
         mail($strContact, $subject, $message, $headers);
}

$formMessage = "Thanks, your message has been sent.";
$senderName = "";
$senderEmail = "";
$senderMessage = "";

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.