Jump to content

Emailing output


totalityventures

Recommended Posts

Hi there hope someone can help. (i'm new to php and sql)

 

I've put together a couple of queries that builds a table.  This table is to go into an email to each user on a database. 

 

I've tested this by outputting the results to a website and it all works fine - it displays the email as I want it to so all I need to do now is set it up so that it can be emailed. 

 

I am struggling with how to build the body string - I can do every bit until the table is built.

 

I basically have an SQL query that I use for the start of the body text (creates $body1, $body2, $body3 (headings of table). and then the following code below and then $body5... etc. for the end of the body.  I then just want to join them together for the email. (which I can do)  But how do I get the whole of the table below into a string ($body4)  - can I just put something around it all?  Using $bodyX just returns the last row as you would expect.

 

Please help

 

Thanks in advance

 

 

 

while($row2 = mysql_fetch_array($sql2)){

 

if ((strtolower($row2["ad_town"]) == strtolower($targettown) OR strtolower($row2["ad_town"]) == strtolower($target2town) OR strtolower($row2["ad_town"]) == strtolower($target3town)) AND (strtolower($row2["ad_townseek"]) == strtolower($mytown) OR strtolower($row2["ad_alttownseek"]) == strtolower($mytown) OR strtolower($row2["ad_altalttownseek"]) == strtolower($mytown))) {

$matchtype = 'Exact';

} ELSE {

$matchtype = 'County';

}

$adverttown = $row2["ad_town"];

$adheadline = $row2["ad_headline"];

$nobeds = $row2["ad_nobeds"];

$rent = $row2["ad_rent"];

$adid = $row2["13"];

 

 

 

$bodyX = '

<tr><td style="width: 10%;">

' . $matchtype . '

<td style="width: 20%;">

' . $adverttown . '

</td><td style="width: 55%;">

' . $adheadline . '

</td><td style="width: 5%; text-align: center;">

' . $nobeds . '

</td><td style="width: 5%; text-align: center;">£

' . $rent . '

</td><td style="width: 5%;text-align: center;"><a href="http://ipropertyswap.co.uk/index.php/home-swap-adverts?page=show_ad&adid=

' . $adid . '

">view</a></td></tr>

';

 

echo $bodyX;

}

Link to comment
https://forums.phpfreaks.com/topic/209784-emailing-output/
Share on other sites

I see..

 

// build an array for your email users
$email[] = ('user1', 'user2', 'user3');

// Do a foreach loop to make sure each user receives an email

foreach....   {

$to = $email; // Who you want the e-mail sent to
$subject = 'Table Output'; // The e-mail subject

$bodyX = '
<tr><td style="width: 10%;">
' . $matchtype . '
<td style="width: 20%;">
' . $adverttown . '
</td><td style="width: 55%;">
' . $adheadline . '
</td><td style="width: 5%; text-align: center;">
' . $nobeds . '
</td><td style="width: 5%; text-align: center;">£
' . $rent . '
</td><td style="width: 5%;text-align: center;"><a href="http://ipropertyswap.co.uk/index.php/home-swap-adverts?page=show_ad&adid=
' . $adid . '
">view</a></td></tr>
';

$headers = 'FROM:[email protected]' . "\r\n"; // Setting the Header here
mail($to, $subject, $bodyX, $headers); // Send the e-mail
} // End foreach

Link to comment
https://forums.phpfreaks.com/topic/209784-emailing-output/#findComment-1095091
Share on other sites

in your example, why not use $bodyX .= instead of just =, as that will append all elements together.  then you can take that echo bodyx out, and use $bodyX for your body of the email. 

 

On a side note, use your mail function similar to this:

 

$header .= "Reply-To: Some One <[email protected]>\r\n";     
$header .= "Return-Path: Some One <[email protected]>\r\n";     
$header .= "From: Some One <[email protected]>\r\n";     
$header .= "Organization: My Organization\r\n";     
$header .= "Content-Type: text/html\r\n";      
mail("[email protected]", "Test Message", "This is my message.", $header); 

 

doing it t his way, you will beat most spam filters.

Link to comment
https://forums.phpfreaks.com/topic/209784-emailing-output/#findComment-1095093
Share on other sites

  • 3 weeks later...

Sorry for the delay in my response but I was on holiday.

 

Thanks for your help guys but I am unfortunately still confused as to how to implement this:

 

There are several loops in my php and this is one embedded in it - I can't put the mailto part within this loop:

 

This part builds a table that forms part of an email - so it could create zero rows up to 100 rows - surely if I put the mailto within this query it would mail the same person several times - once for each row.

 

I was hoping that I could put something around the text I posted along the lines of $bodyY= [and then the posted part] so that I would call this text within another loop when I get to a point where the whole of the body of the email has been created.

 

Really appreciate your help.

Link to comment
https://forums.phpfreaks.com/topic/209784-emailing-output/#findComment-1103937
Share on other sites

  • 2 weeks later...

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.