Jump to content

PHPMailer Help


lional

Recommended Posts

Hi

I am trying to write a script where each mail body has the clients name after the greeting

$result_first = mysqli_query($conn,"SELECT * from clients WHERE profmed = '1' AND email != ''");
   	while ($row_first = mysqli_fetch_assoc($result_first)){

$surname_out = $row_first['surname'];
$email_out = $row_first['email'];
$firstname_out = $row_first['firstname'];
$known_as_out = $row_first['known_as'];
/*print $known_as_out;*/
$complete_name = $firstname_out . ' ' . $surname_out;
$final_msg = $greeting_in_out . ' ' . $known_as_out . '<br /><br />' . $textToStore;
$mail->Subject = $subject_out;
$mail->IsHTML(true);
$mail->Body    = "
<html> 
<head> 
<title></title> 
</head> 
<body>
<table><tr><td>
$final_msg
$mail_sig</table></body></html>";

A quick explanation. The client sends through the greeting that he requires to send which is the variable $greeting_in_out, the persons name $known_as_out and the message ($textToStore) is appended to it.

But $mail->Body only takes the last name pulled from the database.

How can each mail have the persons name on the message

 

Thank you

 

Lional

Link to comment
Share on other sites

Morning,

At the top of the message I want to say Good Morning, John for example

If the table field does not have a value in it then it should just say Good Morning

However what is happening is it is attaching the last name in the Database to all the emails, so if Brian is the last name in the database table all the mails will day Good Morning, Brian instead of that persons individual name

 

Thanks

 

Lional

Link to comment
Share on other sites

Also, this is cleaner:

while ($row_first = mysqli_fetch_assoc($result_first)){

extract($resut_first);

// Your other code here 

}

That way the keys of the assoc array will become variable names without needing to set them each time with $var = $result_first['var'];

 

The extract function is awesome

Edited by Stefany93
Link to comment
Share on other sites

 

I have to disagree. The extract() function with the default flags is actually harmful, because it blindly overwrites any variable that happens to have the same name as one of the array keys. This is perfect for causing nasty bugs and infinite confusion, but you wouldn't want this in your application.

 

When you apply extract() to any kind of user-controlled data, you even end up with a massive security vulnerability, because now it's possible to actively inject variables and manipulate the control flow of the program. See the discussion about the ancient “Register Globals” misfeature (in a sense, extract() is even worse than that).

 

Don't randomly import variables into the symbol table. Just use $row_variable['fieldname']. Yes, that's a few character more than just $fieldname, but it's much safer. And if you don't like typing, use an IDE with autocomplete. ;)

Link to comment
Share on other sites

 

No, no, no, nononononononono ... Nope!

 

Beyond what Jaques1 points out, using extract() can easily lead to messy, unreadable code. Where did all those variables come from, and how can you validate the data you're getting if you're not explicitly stating what you expect? extract() is one of a handful of functions I wish was never included in PHP to begin with.

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.