Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Quote:
In this code I'm passing values from page A to page B using ajax code


function myFunction(id) {

            var host = window.location.hostname;
            // Create our XMLHttpRequest object
            var hr = new XMLHttpRequest();
            // Create some variables we need to send to our PHP file
            var url = "debtorsAjax.aspx";
            var type = "debtors";

            var vars = "invoice_id=" + id + "&host=" + host+"&type=" + type;
            hr.open("POST", url, true);
            // Set content type header information for sending url encoded variables in the request
            hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
            // Access the onreadystatechange event for the XMLHttpRequest object
            hr.onreadystatechange = function () {
                if (hr.readyState == 4 && hr.status == 200) {
                    var return_data = hr.responseText;
                    document.getElementById("modalBody").innerHTML = return_data;
                }
            }
            // Send the data to PHP now... and wait for response to update the status div
            hr.send(vars); // Actually execute the request
        }


On page B I'm taking those values and sending an email using SMTP

Quote:
public bool SendMail()
{
MailMessage msg;
SmtpClient smtp = new SmtpClient(System.Configuration.ConfigurationSettings.AppSettings.Get("smtp").ToString());
MailAddress fromMail = new MailAddress(System.Configuration.ConfigurationSettings.AppSettings.Get("FromMailId").ToString());

MailAddress toMail = new MailAddress(Session["topersonEmail"].ToString());

msg = new MailMessage(fromMail, toMail);
msg.IsBodyHtml = true;
msg.Subject = " collected for (" + Session["CODE"].ToString() + ")";
string strMail = "";
string strSubject = "";

XmlDocument objDoc = new XmlDocument();
objDoc.Load(Server.MapPath("DAL/MailContent.xml"));

XmlNodeList objBody = objDoc.GetElementsByTagName("PAYMENTCOLLECTION");
strMail = objBody[0].InnerText;

strMail = strMail.Replace("#_MailHeader#", "");
strMail = strMail.Replace("#_MailImage#", mailimage);
string strM = strMail.Replace("#_user#", Session["sales_person"].ToString());

msg.Body = strM;

bool isMailSend = false;
try
{
smtp.Send(msg);

isMailSend = true;
}
catch (Exception ex)
{
// getExcecption(ex);
}
return isMailSend;
}</blockqu

Now the mail function is not working. although it works on normal c# page but when i'm sending data using ajax it doesn't work on server. on localhost it works properly

What I have tried:

the mail function is not working. although it works on normal c# page but when i'm sending data using ajax it doesn't work on server. on localhost it works properly
Posted
Comments
sameer549 24-Apr-17 3:43am    
if its working in localhost then it should work on server also,
check your server credentials
and be sure whether ajax request hitting the right path

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