Link to home
Start Free TrialLog in
Avatar of SamDavis
SamDavis

asked on

Creating sendmail email template using checkboxes.

Hi there,

I have a page devised on my site which creates an email which is then sent using PHP's sendmail function.  The email consists of a standard "header" text, and also a standard "footer" text.  

I have also got four checkboxes on the page, which, depending on whether they are clicked or not, will insert four chunks of text in the middle part of the email.

Initially I have been trying the following...  The required elements are $msg_header and $msg_footer and the optional elements are $msg_check1, $msg_check2, $msg_check3 and $msg_check4 - I tried a few "show if checkbox = true" snippets, but I just couldn't do it!  Help please...!


$email = "destination@email.com";
$from_header = "From: Our Site Name <info@oursitename.com>";
$subject = "Our Subject";
$msg_header = "Dear " . $firstname . ",\n\n
This is the header text!\n\n";
$msg_check1 = "This is the optional text for checkbox 1\n\n\";
$msg_check2 = "This is the optional text for checkbox 2\n\n\";
$msg_check3 = "This is the optional text for checkbox 3\n\n\";
$msg_check4 = "This is the optional text for checkbox 4\n\n\";
$msg_footer = "This footer!\n\n";
$message = $msg_check1 . $msg_check2 . $msg_check3 . $msg_check4"; 
(mail($email,$subject,$message,$from_header));

Open in new window

Avatar of SamDavis
SamDavis

ASKER

By the way.... the variables of the actual checkboxes are...

$checkbox1
$checkbox2
$checkbox3
$checkbox4

So, I was trying some kind of...

if ($checkbox1 == 0) ( print "$msg_check1" }

But that didn't work.
1. if ($checkbox1 == 0) ( print "$msg_check1" }

If this is the real chunk of code u are using in test...the print should end with a semi colon.

2. (mail($email,$subject,$message,$from_header));
This is from the snippet of code you provided with question. Why are you enclosing the mail function in brackets?
re: Point 1 - I haven't used this technique, but it's something that I thought might be required to achieve my goal, but it doesn't seem to work.

re: Point 2 - this seems to make no difference to the end result - the emails will still send - I have just seen numerous sendmail snippets of code across the web enclosing the mail function in brackets, so therefore I have followed suit.

Still cannot figure this out.

ASKER CERTIFIED SOLUTION
Avatar of Arty K
Arty K
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Nopius, did a great job.