Jump to content

small syntax problem I can't solve!


illuz1on

Recommended Posts

Hi,

 

Im having problems with the snippet below, the $message part.. can anyone help me with the syntax please?

 

Any help will be much appreciated..

Thanks alot

Chris

 

$message = 'Cape Town Alive - Cape Xtreme Booking Request' <br> 'Name:' . cleanPosUrl($_POST['posName']); . 'Email:' . cleanPosUrl($_POST['posEmail']); . 'Staying:' . cleanPosUrl($_POST['posStaying']); . 'Country:' . cleanPosUrl($_POST['posCountry']); . 'Contact:' . cleanPosUrl($_POST['posContact']); . 'Actvity:' . cleanPosUrl($_POST['posActivity']); . 'Comments:' . cleanPosUrl($_POST['posComments']); 


$headers = "From: ".cleanPosUrl($_POST['posName'])." <".cleanPosUrl($_POST['posEmail']).">\r\n";
$headers .= 'To: '.$yourName.' <'.$yourEmail.'>'."\r\n";
$mailit = mail($to,$subject,$message,$headers);

Link to comment
https://forums.phpfreaks.com/topic/113074-small-syntax-problem-i-cant-solve/
Share on other sites

Here's one way to write it:

<?php
$msg_flds = array('Name','Email','Staying','Country','Contact','Activity','Comments');
$tmp = array();
$tmp[] = 'Cape Town Alive - Cape Xtreme Booking Request';
foreach($msg_flds as $fld)
     $tmp[] = $fld . ': ' . cleanPosUrl($_POST['pos' . $fld]);
$message = implode("<br>\r\n",$tmp);
$tmp = array();
$tmp[] = "From: ".cleanPosUrl($_POST['posName'])." <".cleanPosUrl($_POST['posEmail']).">";
$tmp[] = "To: $yourName <$yourEmail>";
$headers = implode("\r\n",$tmp);

$mailit = mail($to,$subject,$message,$headers);
?>

 

Ken

'Cape Town Alive - Cape Xtreme Booking Request' <br> 'Name:'

There are a few problems with this,

1. The string(s) isn't/aren't enclosed properly

2. HTML in an e-mail message isn't generally going to work unless you specify that the e-mail is HTML-formatted

3. There are extra semi-colons which need to be removed

 

A solution would be something like:

"Cape Town Alive - Cape Xtreme Booking Request\nName:"

Assuming that your MTA auto-converts \n to \r\n, which may be a bad assumption...

Thanks Ken, using your solution there and it works perfectly.

 

Im also puzzling on how to make it send this mail to 2 recipients... at the moment its just the one...

As in, support@ and to support2@

Here is another extract..

 

Thanks again,

Chris

 


$yourName = 'Cape-Town-Alive';
$yourEmail = '[email protected]';
$yourSubject = 'New booking request';

        $to = $yourName;
        $subject = 'New Booking Request: '.cleanPosUrl($_POST['posActivity']);

$msg_flds = array('Name','Email','Staying','Country','Contact','Activity','Text');
$tmp = array();
$tmp[] = 'Cape Town Alive - Cape Xtreme Booking Request';
foreach($msg_flds as $fld)
     $tmp[] = $fld . ': ' . cleanPosUrl($_POST['pos' . $fld]);
$message = implode("\r\n",$tmp);
$tmp = array();
$tmp[] = "From: ".cleanPosUrl($_POST['posName'])." <".cleanPosUrl($_POST['posEmail']).">";
$tmp[] = "To: $yourName <$yourEmail>";
$headers = implode("\r\n",$tmp);
        $mailit = mail($to,$subject,$message,$headers);

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.