I found a call to a php function from javascript on YouTube (https://www.youtube.com/watch?v=23WFRVmzFhY) but seem to have an issue. It doesn't wait for the function to be called. Here is the code where I defined the javascript function. At this point I have already filled the arrays but not done the for each loop yet.
#java script function to call php mail
echo "function php_mail(etype, eml, fees){\n";
echo "var result=\"".eletters($etype, $email, $fees)."\";";
echo "alert(result);\n";
echo "return(false);\n";
echo "}\n";
here is the eletters function in php.
function eletters($etype,$email,$fees){
$showname=cross_field("showinfo","id","showname","1",$sid);
#show Dates
$y=$cnfig[$sid.'shw_days'];
for($x=1;$x<=$cnfig[$sid.'shw_days'];$x++){
$day=explode('|',$cnfig[$sid.'shw_day'.$x]);
if($x==($y))$sdates.=" and ";
if($x==1){
$sdates.= date("F jS, ", strtotime($day[0]));
}elseif($x<$y){
$sdates.= date("jS, ", strtotime($day[0]));
}else{
$sdates.= date("jS, Y", strtotime($day[0]));
}
}
#basic email headers
$headers="From: ".$cnfig['shop_email']."\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . " \r\n";
$headers .= "Reply-to: ".$cnfig['shop_replyemail']."\r\n";
$headers .= "Return-Receipt-To:".$cnfig['shop_replyemail']."\r\n";
if($etype=='a'){#Approved Emails
$subject="Congratulations! Your application for the ".$showname." has been approved";
$bodya = "Hello ".cross_field("dealer","artid","fname","1",$row->artid).",<br>Congratulations! Your Application for the ".$showname." has been approved.<br>We are happy you will be joining us on ".$sdates;
$bodya.="<br>".cross_field("textinfo","tid","infotxt","1",'cap')."<br>".$fees."<br>";
if($cnfig[$sid.'shw_payopt']=='site'){
$bodya.="If you have not yet paid, you can pay the balance of your booth fees online by going to this address <a href=\"http://".$cnfig['domain']."/".$cnfig['art_url']."?p=pbx".$sid."\">href=\"http://".$cnfig['domain']."/".$cnfig['art_url']."?p=pbx".$sid."</a><br><br>";
}else{
$bodya.="If you have not yet paid, please send your money order to: <br>".$cnfig[$sid.'shw_mail']."<br><br>";
}
$bodya.="If you have any questions, please don't hesitate to contact me, ".$cnfig['contact_person']."<br>".$cnfig['shop_replyemail']." Thanks again and see you soon.";
}
#mail ($email, $subject, $bodya, $headers);
echo $email."<br>".$subject."<br>".$headers."<br>".$bodya."<br>";
echo $email." has been sent";
}
when I look at the page source running the whole thing here is what I see in the header where this java script is supposed to be.
<!-- Email Script bits -->
<script type="text/javascript">
var eml = []
var fees = []
eml[1]='marsha@nativeamericanartworks.com'
fees[1]='You signed up for the 10X10 Booth Total Fees $300.00<br>The balance is due by December 31st, 2016'
eml[2]='redironhorse.jbej12@gmail.com'
fees[2]='You signed up for the 10X10 Booth Total Fees $300.00<br>The balance is due by December 31st, 2016'
eml[3]='cgbordeaux@hotmail.com'
fees[3]='You signed up for the 10X10 Booth Total Fees $300.00<br>The balance is due by December 31st, 2016'
eml[4]='bettypadilladine505@gmail.com'
fees[4]='You signed up for the 10X10 Booth Total Fees $300.00<br>The balance is due by December 31st, 2016'
eml[5]='pclrivera@hotmail.com'
fees[5]='You signed up for the Youth with Adult Total Fees $0.00<br>The balance is due by December 31st, 2016'
eml[6]='manyhogansgrl@hotmail.com'
fees[6]='You signed up for the 10X10 Booth Total Fees $300.00<br>The balance is due by December 31st, 2016'
function php_mail(etype, eml, fees){
var result="<br>Congratulations! Your application for the has been approved<br>From:
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
Reply-to:
Return-Receipt-To:
<br>Hello ,<br>Congratulations! Your Application for the has been approved.<br>We are happy you will be joining us on <br><h3><strong><span style="font-family:arial,helvetica,sans-serif">Congratulations! You have been juried and selected for participation. </span></strong></h3>
<p>Booth fees are due in full, May 26th, 2017. After this date, there will be an additional late fee. Please make sure that you have mailed in your Special Event License with your NM CRS Tax ID number. It is required to sell your work. </p>
<h3><strong><span style="font-family:arial,helvetica,sans-serif">We are very excited that you will be joining us on August 17-19, 2017. We are looking forward to this year’s event and anticipate a wonderful show showcasing Native fine art. </span></strong></h3>
<p><strong>If you have any questions, please don't hesitate to contact Paula Mirabal, pclrivera@hotmail.com.</strong></p>
<br><br>If you have not yet paid, please send your money order to: <br><br><br>If you have any questions, please don't hesitate to contact me, <br> Thanks again and see you soon.<br> has been sent";
alert(result);
return(false);
}
</script>
but when I look at the page source the result of the function is showing in the var result= bit? What did I do wrong here? from what I read the function should not execute until I call the javascript function?
found I had the email echoing from the php function but that still doesn't explain why its firing without the java script function it is contained in being called/invoked.