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
https://forums.phpfreaks.com/topic/250711-php-email-row-from-mysql/
Share on other sites

  • 2 months later...

Hi,

 

is $contacts an array ?

 

if its not explode it. for example

 

$strContacts = "[email protected], [email protected], [email protected]";

$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 = "";

 

 

Archived

This topic is now archived and is closed to further replies.

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