having trouble setting up phpMailer 5.1

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
The mailer code works perfectly on my pc http://localhost/fab/public/request.php, however i am battling to get it to work on http://ferrety.pcriot.com/public/request.php, the AJAX won't even give a response!

i am battling even to get an XML response, so i can't even see what the problem is! i think it could also be that it times out... in the following posts are the js and php/xml responders.

Yet on my local machine, it works perfectly, same directory structure (cept the site is in a FAB directory on my PC... what am i doing wrong? could it be cos the faFAB directory (www here) contains the lib directory? should it rather be alongside the www directory?

attached please find the phpmailer zip that i am using, recently downloaded from sourceforge.
 

Attachments

  • PHPMailer_v5.1.zip
    109.1 KB · Views: 41
Last edited:

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
the javascript and php source that won't even get an html response in firefox!

Code:
// Request AJAX & DHTML
// xml request
var http_request = false;
var parents = new Array();
function makeRequest(method, url, parameters) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			// set type accordingly to anticipated content type
			http_request.overrideMimeType('text/xml');
			//http_request.overrideMimeType('text/html');
		}
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Cannot create XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = alertContents;
	url += (method=="GET")?parameters:"";
	http_request.open(method, url, true);
	if (method == "POST") {
		http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		http_request.setRequestHeader("Content-length", parameters.length);
		http_request.setRequestHeader("Connection", "close");
	}
	http_request.send((method=="GET")?null:parameters);
}
// xml parser
function alertContents() {
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			var xmldoc = http_request.responseXML;
			alert(this.responseText);
			var rows1 = xmldoc.getElementsByTagName("service");
			for (var r = 0; r < rows1.length; r++) {
				var i = 0;
				var len = parseInt(rows1[r].childNodes.length / 2);
				var arr = new Array(len);
				for (var c = 0; c < rows1[r].childNodes.length; c++) {
					var service = rows1[r].childNodes[c];
					if (service.childNodes.length > 0) {
						arr[i] = service.firstChild.data;
						i++;
					}
				}
				//alert(arr);
				addservice(arr);
			}
			var rows2 = xmldoc.getElementsByTagName("region");
			for (var r = 0; r < rows2.length; r++) {
				var i = 0;
				var len = parseInt(rows2[r].childNodes.length / 2);
				var arr = new Array(len);
				for (var c = 0; c < rows2[r].childNodes.length; c++) {
					var region = rows2[r].childNodes[c];
					if (region.childNodes.length > 0) {
						arr[i] = region.firstChild.data;
						i++;
					}
				}
				//alert(arr);
				addregion(arr);
			}
			var rows3 = xmldoc.getElementsByTagName("attribute");
			for (var r = 0; r < rows3.length; r++) {
				var attribute = rows3[r];
				var arr = new Array();
				for (var a = 0; a < attribute.attributes.length; a++) {
					arr[a] = attribute.attributes[a].value;
				}
				//alert(arr);
				addattribset(arr);
			}
			var rows4 = xmldoc.getElementsByTagName("regions");
			for (var r = 0; r < rows4.length; r++) {
				var region = rows4[r];
				var arr = new Array();
				for (var a = 0; a < region.attributes.length; a++) {
					arr[a] = region.attributes[a].value;
				}
				//alert(arr);
				addregionset(arr);
			}
			// mailer response
			if (xmldoc.getElementsByTagName("result")[0]) {
				if (xmldoc.getElementsByTagName("result")[0].firstChild) {
					var result = xmldoc.getElementsByTagName("result")[0].firstChild.data;
					if (trim(result) != "") alert(result);
				}
			}
			// mysql queries / failures
			if (xmldoc.getElementsByTagName("sql")[0]) if (xmldoc.getElementsByTagName("sql")[0].firstChild) var sql = xmldoc.getElementsByTagName("sql")[0].firstChild.data; if (sql != "") alert(sql);
		} else {
			alert('There was a problem with the request.');
		}
		document.getElementById("ajaxbg").style.visibility = "hidden";
	}
}
// instantiate ajax requests
function ajaxRequest(job) {
	document.getElementById("ajaxbg").style.visibility = "visible";
	switch (job) {
		case "Services Attributes":
			if (trim(document.form_leadsub.menu_services.options[document.form_leadsub.menu_services.selectedIndex].value) == 0) {
				//alert("You have to select a service!");
				document.getElementById("ajaxbg").style.visibility = "hidden";
				document.form_leadsub.menu_services.focus();
				return false;
			}
			var poststr = "menu_services=" + encodeURIComponent(document.form_leadsub.menu_services.options[document.form_leadsub.menu_services.selectedIndex].value);
			makeRequest("POST", "../scripts/request_handler.php?q=1", poststr);
			break;
		case "Lead Submit":
			if (trim(document.form_leadsub.menu_services.options[document.form_leadsub.menu_services.selectedIndex].value) == 0) {
				alert("You have to select a service!");
				document.getElementById("ajaxbg").style.visibility = "hidden";
				document.form_leadsub.menu_services.focus();
				return false;
			}
			if (trim(document.form_leadsub.text_consumerfullname.value) == "") {
				alert("You can't leave your name blank!");
				document.getElementById("ajaxbg").style.visibility = "hidden";
				document.form_leadsub.text_consumerfullname.focus();
				return false;
			}
			var eml = document.form_leadsub.text_consumeremail.value;
			if (trim(eml) == "") {
				alert("You can't leave your e-mail address blank!");
				document.getElementById("ajaxbg").style.visibility = "hidden";
				document.form_leadsub.text_consumeremail.focus();
				return false;
			}
			var invalidChars = " /:,;'\"`~!?#$£€¥%^&*()+=";
			for (var i = 0; i < invalidChars.length; i++) {
				badChar = invalidChars.charAt(i);
				if (eml.indexOf(badChar,0) != -1) {
					alert("Invalid '"+badChar+"' character detected in e-mail!");
					document.getElementById("ajaxbg").style.visibility = "hidden";
					document.form_leadsub.text_consumeremail.focus();
					return false;
				}
				var atPos = eml.indexOf("@",1);
				if (atPos==-1) {
					alert("No @ symbol detected in e-mail!");
					document.getElementById("ajaxbg").style.visibility = "hidden";
					document.form_leadsub.text_consumeremail.focus();
					return false;
				}
				if (eml.indexOf("@",atPos+1)!=-1) {
					alert("Duplicate @ symbol detected in e-mail!");
					document.getElementById("ajaxbg").style.visibility = "hidden";
					document.form_leadsub.text_consumeremail.focus();
					return false;
				}
				dotPos = eml.indexOf(".",atPos);
				if (dotPos <= 0 || dotPos+3>eml.length) {
					alert("Invalid . position detected in e-mail!");
					document.getElementById("ajaxbg").style.visibility = "hidden";
					document.form_leadsub.text_consumeremail.focus();
					return false;
				}
			}
			for (var i = 0; i < document.form_leadsub.attribute.length; i++) {
				if (document.form_leadsub.attribute[i].options[document.form_leadsub.attribute[i].selectedIndex].value == 0) {
					alert("Invalid " + document.form_leadsub.attribute[i].options[0].text.replace("* Select ","") + " value detected!");
					document.getElementById("ajaxbg").style.visibility = "hidden";
					document.form_leadsub.attribute[i].focus();
					return false;
				}
			}
			if (document.form_leadsub.menu_regions.options[document.form_leadsub.menu_regions.selectedIndex].value == 0) {
				alert("You have to select a region!");
				document.getElementById("ajaxbg").style.visibility = "hidden";
				document.form_leadsub.menu_regions.focus();
				return false;
			}
			if (trim(document.form_leadsub.text_leadsubject.value) == "") {
				alert("You can't leave the subject blank!");
				document.getElementById("ajaxbg").style.visibility = "hidden";
				document.form_leadsub.text_leadsubject.focus();
				return false;
			}
			if (trim(document.form_leadsub.text_leadmessage.value) == "") {
				alert("You can't leave the message blank!");
				document.getElementById("ajaxbg").style.visibility = "hidden";
				document.form_leadsub.text_leadmessage.focus();
				return false;
			}
			var poststr = "menu_services=" + encodeURIComponent(document.form_leadsub.menu_services.options[document.form_leadsub.menu_services.selectedIndex].value) +
						  "&text_consumerfullname=" + encodeURIComponent(document.form_leadsub.text_consumerfullname.value) +
						  "&text_consumeremail=" + encodeURIComponent(document.form_leadsub.text_consumeremail.value);
						  for (var i = 0; i < document.form_leadsub.attribute.length; i++) {
						       poststr += "&attribute[]=" + encodeURIComponent(document.form_leadsub.attribute[i].options[document.form_leadsub.attribute[i].selectedIndex].value);
						  }
			poststr    += "&menu_regions=" + encodeURIComponent(document.form_leadsub.menu_regions.options[document.form_leadsub.menu_regions.selectedIndex].value) +
						  "&text_leadsubject=" + encodeURIComponent(document.form_leadsub.text_leadsubject.value) +
						  "&text_leadmessage=" + encodeURIComponent(document.form_leadsub.text_leadmessage.value);
			//alert(poststr);
			makeRequest("POST", "../scripts/request_handler.php?q=2", poststr);
			break;
		default:
			makeRequest("GET", "../scripts/request_handler.php?q=0", "");
			document.form_leadsub.text_consumerfullname.value = "";
			document.form_leadsub.text_consumeremail.value = "";
			document.form_leadsub.menu_services.options.length = 1;
			// clear attributes
			document.getElementById("fieldset_attributes").innerHTML = "\n  <legend>Service Attri<u>b</u>utes</legend>\n";
			document.form_leadsub.menu_regions.options.length = 1;
			document.form_leadsub.text_leadsubject.value = "";
			document.form_leadsub.text_leadmessage.value = "";
	}
}
 
Last edited:

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
the javascript and php source that won't even get an html response in firefox!

Code:
// string trim functions
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}
function ltrim(str, chars) {
    if (chars == undefined) var chars = "";
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
function rtrim(str, chars) {
    if (chars == undefined) var chars = "";
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
// leftpadding for tree display
function strRepeat(str, len) {
    var ret = "";
    for (i = 0; i < len; i++) {
        ret += str;
    }
    return ret;
}
// dynamic updaters
function addservice(arr) {
    var opt = document.createElement('option');
    opt.text = arr[1];                // service name
    opt.value = arr[0];                // service id
    var sel = document.getElementById("menu_services");
    try {
        sel.add(opt, null);            // standards compliant; doesn't work in IE
    }
    catch(ex) {
        sel.add(opt);                // IE only
    }
}
function addregion(arr) {
    var opt = document.createElement('option');
    //alert(arr[2]);
    opt.text = strRepeat("\u00a0\u00a0\u00a0\u00a0\u00a0",
               arr[3]) + arr[2];    // region indent and name
    opt.value = arr[0];                // region id
    opt.disabled = "true";
    var sel = document.getElementById("menu_regions");
    try {
        sel.add(opt, null);            // standards compliant; doesn't work in IE
    }
    catch(ex) {
        sel.add(opt);                // IE only
    }
}
function addattribset(arr) {
    // create new select named attribute[n];
    var p = document.createElement('p');
    var sel = document.createElement('select');
    sel.id = "attribute";
    sel.name = "attribute";
        var opt = document.createElement('option');
        opt.text = "* Select " + arr[0];
        opt.value = 0;
        try {
            sel.add(opt, null);            // standards compliant; doesn't work in IE
        }
        catch(ex) {
            sel.add(opt);                // IE only
        }
    for (var i = 1; i < arr.length; i++) {
        opt = document.createElement('option');
        opt.text = arr[i].split(";")[1];
        opt.value = arr[i].split(";")[0];
        try {
            sel.add(opt, null);            // standards compliant; doesn't work in IE
        }
        catch(ex) {
            sel.add(opt);                // IE only
        }
    }
    p.appendChild(sel);
    document.getElementById("fieldset_attributes").appendChild(p);
}
function addregionset(arr) {
    for (var i = 1; i < document.form_leadsub.menu_regions.options.length; i++) {
        for (var a = 0; a < arr.length; a++) {
            if (document.form_leadsub.menu_regions.options[i].value == arr[a]) {
                document.form_leadsub.menu_regions.options[i].disabled = false;
            }
        }
    }
}
function disableallregions() {
    for (var i = 1; i < document.form_leadsub.menu_regions.options.length; i++) {
        document.form_leadsub.menu_regions.options[i].disabled = true;
    }
}
// onload event handler
window.onload = function () {
    return ajaxRequest("Load Form");
}
// onselect event handler
document.form_leadsub.menu_services.onchange = function () {
    // clear attributes
    document.getElementById("fieldset_attributes").innerHTML = "\n  <legend>Service Attri<u>b</u>utes</legend>\n";
    // disable all regions
    disableallregions();
    return ajaxRequest("Services Attributes");
}

i use relative urls for the site files, so they should all work. i've even tried uploading the fiiles alongside phpmailer but with no difference... i've got the db connection right as all else works (it loads the current services, suppliers and regions etc from the xml responder).
i'm definately not doing something right on x10hosting. please help me out? :)
below is the php xml responder:

PHP:
<?php
// discover which processing to do, otherwise do default (loading)
$q = $_GET["q"];
if (is_numeric($q)) {
    if ($q > 8 || $q < 0) {
        $q = 0;
    }
} else {
    $q = 0;
}
// initiate sql query & associated error store
$sql = "";
// connect to mysql and select database
$conn = mysql_connect("localhost", "****", "****"); // LOCALHOST
//$conn = mysql_connect("localhost", "****", "****"); // FERRETY.PCRIOT.COM
if (!$conn) {
    die("Could not connect: " . mysql_error());
}
mysql_select_db("****", $conn);
// get single region name
function getregionname($id) {
    $sql = "SELECT * FROM 1_regions WHERE bigint_RegionID = ".$id.";\n";
    $GLOBALS["sql"] .= $sql;
    $result = mysql_query($sql);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    while ($row = mysql_fetch_array($result)) {
        return $row["text_RegionDescription"];
    }
    return "REGION NOT FOUND";
}
// parse selected attribute descriptions = value form elements array
function getattribs($arr) {
    $arr2 = array();
    foreach ($arr as $val) {
        $sql = "SELECT bigint_AttributeID, text_AttributeDescription, text_AttributeValue FROM 3_serviceattributes WHERE bigint_AttributeID = ".$val.";\n";
        $GLOBALS["sql"] .= $sql;
        $result = mysql_query($sql);
        $err = mysql_error();
        $GLOBALS["sql"] .= strtoupper($err)."\n";
        while ($row = mysql_fetch_array($result)) {
            array_push($GLOBALS["attribids"],$row["bigint_AttributeID"]);
            array_push($arr2,$row["text_AttributeDescription"]." = ".$row["text_AttributeValue"]);
        }
    }
    return join("<br />",$arr2);
}
// load all services to choose from
function getallservices() {
    $sql = "SELECT * FROM 2_servicescatalogue ORDER BY text_ServiceDescription ASC;\n";
    $GLOBALS["sql"] .= $sql;
    $result = mysql_query($sql);
    if ($result) {
        while ($row = mysql_fetch_array($result)) {
            echo "    <service>\n";
            echo "        <serviceid>" . $row["bigint_ServiceID"] . "</serviceid>\n";
            echo "        <servicedescription>" . htmlentities($row["text_ServiceDescription"]) . "</servicedescription>\n";    
            echo "    </service>\n";
        }
    }
}
// load all regions to choose from
function getallregions($level,$pid) {
    $sql = "SELECT * FROM 1_regions WHERE bigint_ParentRegionID = ".$pid." ORDER BY text_RegionDescription ASC;\n";
    $GLOBALS["sql"] .= $sql;
    $result = mysql_query($sql);
    if ($result) {
        while ($row = mysql_fetch_array($result)) {
            echo "    <region>\n";
            echo "        <regionid>" . $row["bigint_RegionID"] . "</regionid>\n";
            echo "        <regionparent>" . $row["bigint_ParentRegionID"] . "</regionparent>\n";
            echo "        <regionname>" . htmlentities($row["text_RegionDescription"]) . "</regionname>\n";
            echo "        <indent>" . $level . "</indent>\n";
            echo "    </region>\n";
            getallregions($level+1, $row["bigint_RegionID"]);
        }
    }
}
// load attributes and possible values into xml
function getattributes($s) {
    $sql = "SELECT DISTINCT text_AttributeDescription FROM 3_serviceattributes WHERE bigint_AttributeServiceID = ".$s." ORDER BY text_AttributeDescription ASC;\n";
    $GLOBALS["sql"] .= $sql;
    $result = mysql_query($sql);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    if ($result) {
        while ($row = mysql_fetch_array($result)) {
            $sql1 = "SELECT bigint_AttributeID, text_AttributeValue FROM 3_serviceattributes WHERE text_AttributeDescription = \"".mysql_real_escape_string($row["text_AttributeDescription"])."\" AND bigint_AttributeServiceID = ".$s." ORDER BY text_AttributeValue ASC;\n";
            $GLOBALS["sql"] .= $sql;
            $result1 = mysql_query($sql1);
            $err = mysql_error();
            $GLOBALS["sql"] .= strtoupper($err)."\n";
            echo "    <attribute description=\"".$row["text_AttributeDescription"]."\" ";
            if ($result1) {
                $i = 0;
                while ($row1 = mysql_fetch_array($result1)) {
                    echo "value".$i."=\"".$row1["bigint_AttributeID"].";".$row1["text_AttributeValue"]."\" ";
                    $i++;
                }
                echo "/>\n";
            }
        }
    }
}
 
Last edited:

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
the javascript and php source that won't even get an html response in firefox!

PHP:
// load available child regions
function getregions($id) {
    $sql1 = "SELECT * FROM 1_regions WHERE bigint_ParentRegionID = ".$id.";\n";
    $GLOBALS["sql"] .= $sql1;
    $result1 = mysql_query($sql1);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    if ($result1) {
        while ($row = mysql_fetch_array($result1)) {
            echo "enabled".$row["bigint_RegionID"]."=\"".$row["bigint_RegionID"]."\" ";
            getregions($row["bigint_RegionID"],false);
        }
    }
}
// load a mail template
function getFile($filename) {
    $return = '';
    if ($fp = fopen($filename,'rb')) {
    $return = fread($fp, filesize($filename));
    fclose($fp);
        return $return;
    } else {
        return false;
    }
}
// get a chunk of text between two tags
function getSubText($body, $tagstart, $tagend) {
    $startpos = strpos($body, $tagstart) + strlen($tagstart);
    $sublen   = strpos($body,$tagend) - $startpos;
    return substr($body,$startpos,$sublen);
}
// populate region id's
function getregionsarr($id) {
    $sql1 = "SELECT * FROM 1_regions WHERE bigint_ParentRegionID = ".$id.";\n";
    $GLOBALS["sql"] .= $sql1;
    $result1 = mysql_query($sql1);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    if ($result1) {
        while ($row = mysql_fetch_array($result1)) {
            array_push($GLOBALS["regionids"], $row["bigint_RegionID"]);
            getregionsarr($row["bigint_RegionID"]);
        }
    }
}
// check wether a supplier is in a region or not
function inregion($supplierid) {
    $sql = "SELECT * FROM 9_supplierattributes WHERE bigint_SupplierID = ".$supplierid.";\n";
    $GLOBALS["sql"] .= $sql;
    $result = mysql_query($sql);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    if ($result) {
        while ($row = mysql_fetch_array($result)) {
            if (in_array($row["bigint_RegionID"],$GLOBALS["regionids"])) {
                return true;
            }
        }
        return false;
    } else {
        return false;
    }
}
// check wether a supplier has a specific attribute
function hasattrib($supplierid,$attribid) {
    $ret = false;
    $sql = "SELECT * FROM 9_supplierattributes WHERE bigint_SupplierID = ".$supplierid." AND bigint_ServiceID = ".$GLOBALS["service"]." AND bigint_AttributeID = ".$attribid.";\n";
    $GLOBALS["sql"] .= $sql;
    $result = mysql_query($sql);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    if ($result) {
        while ($row = mysql_fetch_array($result)) {
            $ret = true;
        }
    }
    return $ret;
};
// check wether supplier has all attributes
function hasattribs($supplierid) {
    $ret = true;
    foreach ($GLOBALS["attribids"] as $attribid) {
        if (!hasattrib($supplierid,$attribid)) {
            $ret = false;
        }
    }
    return ret;
}
// check wether a supplier has been linked to a service
function hasservice($supplierid) {
    $ret = false;
    $sql = "SELECT * FROM 4_servicesuppliers WHERE bigint_SupplierID = ".$supplierid." AND bigint_ServiceID = ".$GLOBALS["service"].";\n";
    $GLOBALS["sql"] .= $sql;
    $result = mysql_query($sql);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    if ($result) {
        while ($row = mysql_fetch_array($result)) {
            $ret = true;
        }
    }
    return $ret;
}
// load all suppliers
function getsuppliers() {
    $sql1 = "SELECT * FROM 5_suppliers;\n";
    $GLOBALS["sql"] .= $sql1;
    $result1 = mysql_query($sql1);
    $err = mysql_error();
    $GLOBALS["sql"] .= strtoupper($err)."\n";
    if ($result1) {
        while ($row1 = mysql_fetch_array($result1)) {
            if (inregion($row1["bigint_SupplierID"]) && hasattribs($row1["bigint_SupplierID"]) && hasservice($row1["bigint_SupplierID"])) {
                array_push($GLOBALS["mailadds"], $row1["text_ContactFirstName"]." ".$row1["text_ContactSurname"].";".$row1["text_SupplierName"].";".$row1["text_ContactE-mail"].";".$row1["bigint_CurrentBalance"]);
                array_push($GLOBALS["supplierids"], $row1["bigint_SupplierID"]);
            }
        }
    }
}
 
Last edited:

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
the javascript and php source that won't even get an html response in firefox!

PHP:
// start outputting xml and processing according to query made
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<root>\n";
switch ($q) {
    case 1: // load available regions
        $service = $_POST["menu_services"];
        getattributes($service);
        $sql1 = "SELECT * FROM 4_servicesuppliers WHERE bigint_ServiceID = ".$service;
        $sql .= $sql1;
        $result1 = mysql_query($sql1);
        $err = mysql_error();
        $sql .= strtoupper($err)."\n";
        if ($result1) {
            while ($row1 = mysql_fetch_array($result1)) {
                echo "    <regions enabled".$row1["bigint_RegionID"]."=\"".$row1["bigint_RegionID"]."\" ";
                getregions($row1["bigint_RegionID"]);
                echo "/>\n";
            }
        }
        break;
    case 2: // submit a request
        $regionids = array();
        $supplierids = array();
        $mailadds = array();
        $attribids = array();
        $suppliers = array();
        $failure = 0;
        $success = 0;
        $errmsg = array();
        $scsmsg = array();
        $consumerfullname = mysql_real_escape_string($_POST["text_consumerfullname"]);
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $consumeremail = mysql_real_escape_string($_POST["text_consumeremail"]);
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $service = $_POST["menu_services"];
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $region = $_POST["menu_regions"];
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $regionname = mysql_real_escape_string(getregionname($region));
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $subject = mysql_real_escape_string($_POST["text_leadsubject"]);
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $attribs = mysql_real_escape_string(getattribs($_POST["attribute"]));
        //echo $attribs;
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $message = mysql_real_escape_string($_POST["text_leadmessage"]);
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $sql0 = "SELECT * FROM 2_servicescatalogue WHERE bigint_ServiceID = ".$service.";\n";
        //die (sprintf('%s :: %s',__FILE__,__LINE__));
        $sql .= $sql0;
        $result0 = mysql_query($sql0);
        $err = mysql_error();
        $sql .= strtoupper($err)."\n";
        if ($result0) {
            while ($row0 = mysql_fetch_array($result0)) {
                $servicename = $row0["text_ServiceDescription"];
                $servicecost = $row0["bigint_CostPerLead"];
            }
        }
        $consumerfullname        = $_POST["text_consumerfullname"];                                // rerequest consumer full name
        $consumeremail            = $_POST["text_consumeremail"];                                    // rerequest consumer email
        $tsql = "SELECT * FROM 7_blacklist WHERE `text_E-mailAddress` = \"".$consumeremail."\";\n";
        $sql .= $tsql;
        $result = mysql_query($tsql);
        $err = mysql_error();
        $sql .= strtoupper($err)."\n";
        if ($result) {
            if (mysql_num_rows($result) > 0) {
                    echo "    <result>\n";
                    echo "Your e-mail address has been blacklisted for inappropriate use of Ferrety.co.za by the administrators.\n\n".
                         "Please contact Jaap Venter at jaap.venter@ananzi.co.za for more information.";
                    echo "    </result>\n";
            } else {
                $subject                = $_POST["text_leadsubject"];                                    // rerequest subject
                $message                = str_replace("\r\n","<br>\r\n",$_POST["text_leadmessage"]);    // rerequest message
                array_push($regionids,$region);
                getregionsarr($region);
                getsuppliers($service);
                //die (sprintf('%s :: %s',__FILE__,__LINE__));
                include("../includes/mailer/class.phpmailer.php");                                        // include PHPMailer class
                include("../includes/mailer/class.smtp.php");                                            // note, this is optional - gets called from main class if not already loaded
                $i = 0;                                                                                    // set the counter to start counting at 0
                foreach ($mailadds as $add) {                                                            // loop through available suppliers and their recipients
                    $sql1 = "INSERT INTO 6_serviceleads (text_Consumer, text_LeadSubject, text_LeadAttributes, text_LeadMessage, bigint_ServiceID, bigint_SupplierID, bigint_RegionID) VALUES (\"".$consumerfullname.";".$consumeremail."\",\"".$subject."\",\"".$attribs."\",\"".$message."\",".$service.",".$supplierids[$i].",".$region.");\n";
                    $sql .= $sql1;
                    $result1 = mysql_query($sql1);
                    $err = mysql_error();
                    $sql .= strtoupper($err)."\n";
                    // die (sprintf('%s :: %s',__FILE__,__LINE__));
                    //==========================================================================================================================================================================================================
                    // if lead created successfully, select valid suppliers (matching the requested service regions (and childregions), with the required minimum credit balance) and email the contacts, subtracting credits if successfully mailed and logging the transaction.
                    if (strlen(trim($err))<=0) {
                        $leadid             = mysql_insert_id($conn);                                    // get lead id
                        $body                 = getFile("../templat/lead.html");                            // load mail template
                        $recipient            = split(";",$add);                                            // split contact name, supplier name, and contact email
                        $mail                = new PHPMailer();                                            // create a new object
                        $newbalance            = ($recipient[3]-$servicecost);                                // generate new balance
                        $body = str_replace("%SERVICE%",$servicename,$body);                            // insert service name
                        $body = str_replace("%LID%","#".($leadid + 11001000),$body);                    // insert lead id + 11,001,000
                        $body = str_replace("%SUBJECT%",$subject,$body);                                // insert subject
                        $body = str_replace("%CONTACTNAME%",$recipient[0],$body);                        // insert contact name
                        $body = str_replace("%CONSUMERNAME%",$consumerfullname,$body);                    // insert consumer full name
                        $body = str_replace("%SUPPLIERNAME%",$recipient[1],$body);                        // insert supplier name
                        $body = str_replace("%ATTRIBUTES%",$attribs,$body);                                // insert selected attributes
                        $body = str_replace("%MESSAGE%",$message,$body);                                // insert message
                        $body = str_replace("%REGIONNAME%",$regionname,$body);                            // insert region name
                        $body = str_replace("%CONSUMEREMAIL%",$consumeremail,$body);                    // insert consumer email
                        $body = str_replace("%COST%",$servicecost,$body);                                // insert lead cost
                        $body = str_replace("%BALANCE%",$newbalance,$body);                                // insert supplier balance
                        $mail->IsSMTP();                                                                // enable SMTP
                        $mail->SMTPAuth        = true;                                                        // enable SMTP authentication
                        $mail->SMTPSecure    = "ssl";                                                    // sets the prefix to the servier
                        $mail->Host            = "smtp.gmail.com";                                            // sets GMAIL as the SMTP server
                        $mail->Port            = 465;                                                        // set the SMTP port
                        $mail->Username        = "greywacke24@gmail.com";                                    // GMAIL username
                        $mail->Password        = "Wacker82118";                                            // GMAIL password
                        $mail->From            = $consumeremail;                                            // set from consumer email
                        $mail->FromName        = $consumerfullname;                                        // set from consumer name
                        $body                = str_replace("%SUPPLIER%",$recipient[1],$body);            // insert supplier name
                        $body                = str_replace("%CONTACTNAME%",$recipient[0],$body);            // insert supplier contact name
                        $mail->Subject        = getSubText($body,"<title>","</title>");                    // set subject to template page title
                        $mail->AddReplyTo($consumeremail, $consumerfullname);                            // add the message reply to addresses
 
Last edited:

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
the javascript and php source that won't even get an html response in firefox!

PHP:
                        //$mail->AddReplyTo("pierre@greywacke.co.za", "Pierre \"Greywacke\" du Toit");    // add the developer to the replyto list
                        //$mail->AddReplyTo("jaap.venter@ananzi.co.za", "Jaap Venter");                    // add the owner to the replyto list
                        $mail->ClearAttachments();                                                        // clears attachments
                        $mail->AddEmbeddedImage("../templat/tikilogo.png","0x000000","tikilogo");        // add the ferrety logo to the message
                        $mail->AddEmbeddedImage("../templat/mail_bg.jpg","0x000001","mail_bg");            // add the background image to the message
                        $mail->MsgHTML($body);                                                            // set HTML Body
                        $mail->AltBody = strip_tags(html_entity_decode(getSubText($body,                // set Text Body
                        "<body>","</body>")));
                        $mail->AddAddress($recipient[2], $recipient[0]);                                // add recipient
                        array_push($suppliers, $recipient[1]);                                            // push success supplier array
                        $mail->IsHTML(true);                                                            // set send as HTML
                        if(!$mail->Send()) {                                                            // if attempt sending failed   
                            array_push($errmsg,"FAILURE: ".$recipient[0].", ".$recipient[2].            // save error report
                            " (".$mail->ErrorInfo.")");
                            $failure++;                                                                    // increment failures counter
                        } else {                                                                        // successfully sent, subtract credits and report success.
                            $sql2 = "UPDATE 5_suppliers SET bigint_CurrentBalance = ".$newbalance." WHERE bigint_SupplierID = ".$supplierids[$i].";\n";
                            $sql .= $sql2;                                                                // archive new balance sql statement
                            $result2 = mysql_query($sql2);                                                // subtract credits
                            $err = mysql_error();                                                        // retrieve mysql error
                            $sql .= strtoupper($err)."\n";                                                // archive mysql error
                            $sql3 = "UPDATE 6_serviceleads SET tinyint_LeadSent = 1 WHERE bigint_LeadID = ".$leadid.";\n";
                            $sql .= $sql3;                                                                // archive leadsent sql statement
                            $result3 = mysql_query($sql3);                                                // mark lead as sent
                            $err = mysql_error();                                                        // retrieve mysql error
                            $sql .= strtoupper($err)."\n";                                                // archive mysql error
                            $sql4 = "INSERT INTO 8_transactions (bigint_SupplierID, bigint_LeadID, bigint_TransactionAmount, bigint_TransactionBalance) VALUES (".$supplierids[$i].",".$leadid.",".$servicecost.",".$newbalance.");\n";
                            $sql .= $sql4;                                                                // archive transaction sql statement
                            $result3 = mysql_query($sql4);                                                // archive transaction
                            $err = mysql_error();                                                        // retrieve mysql error
                            $sql .= strtoupper($err)."\n";                                                // archive mysql error
                            array_push($errmsg,"SUCCESS: ".$recipient[0].", ".$recipient[2]);            // save success report
                            array_push($scsmsg, $recipient[1]);                                            // push successful suppliers array
                            $success++;                                                                    // increment success counter
                        }
                        $i++;
                    }
                }
                $body                 = getFile("../templat/response.html");                        // load mail template
                $mail                = new PHPMailer();                                            // create a new object
                $body = str_replace("%SUBJECT%",$subject,$body);                                // insert subject
                $body = str_replace("%CONSUMERNAME%",$consumerfullname,$body);                    // insert consumer full name
                $body = str_replace("%SUPPLIERLIST%",join("<br />",$suppliers),$body);                    // insert supplier list
                $body = str_replace("%SUCCESSLIST%",join("<br />",$scsmsg),$body);                        // insert success list
                $body = str_replace("%SUCCESSCOUNT%",$success,$body);                            // insert success count
                $body = str_replace("%REGIONNAME%",$regionname,$body);                            // insert region name
                $body = str_replace("%CONSUMEREMAIL%",$consumeremail,$body);                    // insert consumer email
                $body = str_replace("%SERVICE%",$servicename,$body);                            // insert service name
                $body = str_replace("%ATTRIBUTES%",$attribs,$body);                                // insert selected attributes
                $body = str_replace("%MESSAGE%",$message,$body);                                // insert message
                $mail->IsSMTP();                                                                // enable SMTP
                $mail->SMTPAuth        = true;                                                        // enable SMTP authentication
                $mail->SMTPSecure    = "ssl";                                                    // sets the prefix to the servier
                $mail->Host            = "smtp.gmail.com";                                            // sets GMAIL as the SMTP server
                $mail->Port            = 465;                                                        // set the SMTP port
                $mail->Username        = "greywacke24@gmail.com";                                    // GMAIL username
                $mail->Password        = "Wacker82118";                                            // GMAIL password
                $mail->From            = "no-reply@ferrety.co.za";                                    // set from consumer email
                $mail->FromName        = "Ferrety.co.za";                                            // set from consumer name
                $mail->Subject        = getSubText($body,"<title>","</title>");                    // set subject to template page title
                //$mail->AddReplyTo($consumeremail, $consumerfullname);                            // add the message reply to addresses
                //$mail->AddReplyTo("pierre@greywacke.co.za", "Pierre \"Greywacke\" du Toit");    // add the developer to the replyto list
                $mail->AddReplyTo("jaap.venter@ananzi.co.za", "Jaap Venter");                    // add the owner to the replyto list
                $mail->ClearAttachments();                                                        // clears attachments
                $mail->AddEmbeddedImage("../templat/tikilogo.png","0x000000","tikilogo");        // add the ferrety logo to the message
                $mail->AddEmbeddedImage("../templat/mail_bg.jpg","0x000001","mail_bg");            // add the background image to the message
                $mail->MsgHTML($body);                                                            // set HTML Body
                $mail->AltBody = strip_tags(html_entity_decode(getSubText($body,                // set Text Body
                "<body>","</body>")));
                $mail->AddAddress($recipient[2], $recipient[0]);                                // add recipient
                $mail->IsHTML(true);                                                            // set send as HTML
                if(!$mail->Send()) {                                                            // if attempt sending failed
                    array_push($errmsg,"FAILURE: ".$recipient[0].", ".$recipient[2].            // save error report
                    " (".$mail->ErrorInfo.")");
                    $failure++;                                                                    // increment failures counter
                } else {
                    array_push($errmsg,"SUCCESS: ".$consumerfullname.", ".$consumeremail);        // save success report
                    $success++;                                                                    // increment success counter
                }
                echo "    <result>\n";
                echo "A total of ".$failure." e-mails failed to send, however ".$success." e-mails were successfully sent to the following recipients, e-mail addresses (errors are displayed in brackets):\n";
                $i = 1;
                foreach ($errmsg as $errm) {
                    echo $i.".) ".$errm."\n";
                    $i++;
                }
                echo "    </result>\n";
            }
        }
        break;
    default: // load starting information (services and regions)
        getallservices();
        getallregions(0,0);
}
 
Last edited:

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
the javascript and php source that won't even get an html response in firefox!

PHP:
echo "    <sql>\n" . $sql . "    </sql>\n";
echo "</root>";
mysql_close($conn);
?>
any possible way i could make case 2 a bit faster? the processing time should be under 1 minute, it normally is on my pc - even less here! it could be possible that i am missing something, that it can't find a matching supplier.
 
Last edited:

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
where would i check that?
i believe it would be off if it needs to be implicitly set.
Edit:
or rather how can i request it be changed for ferrety.pcriot.com?
Edit:
okay i doubt that could be the problem... php mailer 5.1 is for php 5/6. yet it works on my pc at home with register_globals = Off
something else is the matter here...
 
Last edited:

xgreenberetx

New Member
Messages
57
Reaction score
1
Points
0
I just checked the site, and it is weird how the alert pops up your source code, acts like it loading then another alert with more source code. I would check there for problems.
 

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
thats meant to be so, mr. xgreenberetx - my AJAX script is in debugging mode so it alerts the source xml and sql queries made. here are the lines that do that, usually they are commented. they are in the alertContents() function in Part 1/6 - containing the first bit of javascript. as i said earlier, the problem is with getting phpmailer 5.1 to work on x10hosting.com, it is not register_globals cos that is off on my side as is it here - yet phpmailer installed successfully on my xampp 1.7.2.

Code:
 // this is just after the receipt of the response, wether xml or containing a php error
alert(this.responseText);

            // mailer response used to output phpmail successes and failures
            if (xmldoc.getElementsByTagName("result")[0]) {
                if (xmldoc.getElementsByTagName("result")[0].firstChild) {
                    var result = xmldoc.getElementsByTagName("result")[0].firstChild.data;
                    if (trim(result) != "") alert(result);
                }
            }
            // outputs all the mysql queries / failures processed
            if (xmldoc.getElementsByTagName("sql")[0]) if (xmldoc.getElementsByTagName("sql")[0].firstChild) var sql = xmldoc.getElementsByTagName("sql")[0].firstChild.data; if (sql != "") alert(sql);
// these are further down in the function, alerting the mailer's response and sql queries made
Edit:
see, the problem that i am having, is that when the form is filled out, and you click submit query, that it doesn't even return a response. it should have used phpmailer and its includes to send a mail to the test supplier in the database that is linked to the service with some or all of the attributes provided by it, after it has been matched.
 
Last edited:

lachytv

New Member
Messages
43
Reaction score
1
Points
0
Just throwing this out here with out having a clue with programming but I think dedicated mailing scripts are band if that what you are putting together.

Link
 

cGamez010

New Member
Messages
37
Reaction score
0
Points
0
as far as i know it is not illegal, or someone would have told me in the ticket i have.
well this site is moving onto the live server now anyways, with mysql and non-gmail smtp mail so no more worries there :)
Edit:
as far as i know it is not illegal, or someone would have told me in the ticket i have.
well this site is moving onto the live server now anyways, with mysql and non-gmail smtp mail so no more worries there :)
 
Last edited:
Top