Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys!

My friend is trying to get more people to sign up for his newsletter on ConstantContact, but he also wants to get visitor feedback mailed directly to him.

I have his HTML form posting to a PHP file on the server. That PHP is currently 1/2 working, as it successfully sends an email to me with the visitor comments in it. Now, I just need it to also send the 4 variables along to ConstantContact.

If it was an HTML form directly posting to ConstantContact, the action would be: "action="http://visitor.r20.constantcontact.com/d.jsp" but it is PHP, so I assume the syntax is different.

And here is my current PHP file that is successfully 1/2 working:
XML
<?php
$emailSubject = 'Customer Has a Question!';
$webMaster = 'barry@page3design.com';

$ea = $_POST['ea'];
$comments = $_POST ['comments'];
$llr = $_POST ['llr'];
$m = $_POST ['m'];
$p = $_POST ['p'];

$body = <<<EOD
<br><hr><br>
Email: $ea <br>
Comments: $comments <br>
&nbsp;<br>
And below are the four variables sent to Constant Contact:<br>
Email: $ea <br>
LLR: $llr <br>
M: $m <br>
P: $p <br>

&nbsp;<br>
These comments were sent from the test.html page of the JW Secure site. <br>
The visitor has checked the box that would send their information to Constant Contact.<br>
EOD;
$headers = "From: $ea\r\n";
$headers .= "Content-type: text/html\r\n";

$success = mail($webMaster, $emailSubject, $body, $headers);

$theResults = <<<EOD
<META http-equiv="refresh" content="0;URL=http://www.jwsecure.com/contact/thank-you/">
EOD;

echo "$theResults";
?>


And if it helps, here is the form from the HTML. The hidden variables are just things for ConstantContact, so we have values for each of those, we just need to pass them along to CC.

XML
<form action="SendToConstantContact.php" name="myform" method="post" onsubmit="return submitForm(this)">
Your email*:<br/>
<input type="text" name="ea" size="39" value="" style="font-size:10pt;"><br/>
<img src="images/transparent.gif" width="1" height="9" alt="" border="0" /><br/>
Your message (optional):<br/>
<textarea name="comments" cols="30" rows="3" style="font-size:10pt;">
</textarea><br/>
<img src="images/transparent.gif" width="1" height="9" alt="" border="0" /><br/>
<input type="hidden" name="llr" value="z4u4kndab">
<input type="hidden" name="m" value="1103180583929">
<input type="hidden" name="p" value="oi">

<input type="submit" value="Submit" />
</form>


So, my question is, how do I do 2 things in my PHP file? 1. send the email to Dan (this part is working) and 2. also send the variables to ConstantContact via this PHP page (I need help with this part)?

I've tried to find the answer on PHP sites but so far it has eluded me. Thank you for your time and expertise.
-Barry
Posted
Updated 28-Jun-13 14:34pm
v3
Comments
Killzone DeathMan 28-Jun-13 12:37pm    
you have an error there ...
"$questionField" - is unused
"$comments" - is not declared

maybe you mean:
$comments = $_POST ['comments'];
pygmydynamo 28-Jun-13 20:06pm    
I think that is what I mean. Thank you! I've updated the code. -Barry
Killzone DeathMan 28-Jun-13 12:48pm    
Maybe in your friends page must be the fields, and when all are validated, just do something like:

$.ajax({
type: "POST",
url: "youphpfile.php",
data: {"ea":"cliente_mail@example.com", "comments":"So easy!", "llr":"WTFisTHIS", "m":"mmm","p":"ppp"},
success: function(){
alert('Email send successfully!');
},
dataType: "json"
});

This will execute your 1/2 done PHP script to send the email...
want a tip? smoke marijuana and all will be OK! xD
Regards,
KZ
pygmydynamo 28-Jun-13 20:26pm    
Hi KZ! Thanks for the feedback!

I've tried adding this $.ajax in, and replacing the youphpfile.php and client2_mail@example.com, but it causes a white page error when the visitor clicks submit... it just hangs on my php page.

To answer your questions, llr, m, and p are all hidden fields from the HTML form. They're numbers that ConstantContact cares about, apparently. For example,
<input type="hidden" name="m" value="1103180583929">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900