2014-05-21 76 views
0

我有一個網站在線,它沒有完成..發送郵件不在我的網站上工作

我的問題是在底部「聯繫我們」論壇。 其不發送任何郵件..

*中,它正在我的本地主機,我不知道什麼是發送郵件的不同

Java腳本代碼:

function sendEmail_click() { 
       if (Page_ClientValidate()) { 
        // $("#LoadingImage").show(); //Show loading image 
        var settings = { 
         'data': getData(), 
         'url': "Handlers/SendMail.ashx", 
         'contentType': 'application/x-www-form-urlencoded; charset=UTF-8' 
        }; 
        sendEmail(settings); 
       }; 
      } 

      function getData() { 
       var data = { 
        'firstName': $('#txt_fName').val(), 
        'lastName': $('#txt_lName').val(), 
        'phone': $('#txt_phone').val(), 
        'bName': $('#txt_bName').val(), 
        'fromMail': $('#txt_email').val(), 
        'Message': $('#txt_message').val(), 
        'checkBox': $('#chk_ad').prop('checked') 
       }; 
       return data; 
      } 

      function showOrHideLoadingImage(id, action) { 
       if (action == "show") { 
        $("#" + id).show(); 
       } else { 
        $("#" + id).hide(); 
       } 
      } 

      function sendEmail(settings) { 
       var success = false; 

       showOrHideLoadingImage("LoadingImage", "show"); 
       $.ajax({ 
        type: "POST", 
        contentType: settings.contentType, 
        data: settings.data, 
        url: settings.url, 
        dataType: "json", 
        success: function (data) { 
         $('#checkMark').css('display', 'inline').fadeOut(20000); //Show check mark image+text 
         $(".contact_input").each(function() { 
          $(this).val(""); 
         }) 

         success = true; 
        }, 
        error: function (data) { 
         $('#xMark').css('display', 'inline').fadeOut(12000); //Show xMark image+text 
         success = false; 
        } 
       }).always(function() { 
        showOrHideLoadingImage("LoadingImage", "hide"); 
       }); 
       return success; 
      } 

處理程序:

public void ProcessRequest (HttpContext context) { 
    //add try catch 
    // Loads parameters into variables 
    string firstName = context.Request.Form.Get("firstName"); 
    string lastName = context.Request.Form.Get("lastName"); 
    string phone = context.Request.Form.Get("phone"); 
    string bName = context.Request.Form.Get("bName"); 
    string senderEmail = context.Request.Form.Get("fromMail"); 
    string message = context.Request.Form.Get("message"); 
    string chkBox_ad = context.Request.Form.Get("checkBox"); 

    bool mailSent = Mail.SendEmail(firstName, lastName, bName, phone, senderEmail, message, chkBox_ad); 
    context.Response.ContentType = "text/plain"; 

    if (mailSent) 
    { 
     context.Response.Write("true"); 
    } 
    else 
    { 
     context.Response.Write("false"); 

    } 
} 

發送郵件功能:

public static bool SendEmail(string firstName, string lastName, string bName, string phone, string senderEmail, string message, string chkBox_ad) 
{ 
    chkBox_ad = chkBox_ad == "true" ? "..." : "..."; 
    // Email sending 
    string eBody = "..."; 
    eBody += "..."; 
    eBody += "..."; 
    eBody += "..."; 
    eBody += "..."; 
    eBody += "..."; 


    MailMessage MyMailMessage = new MailMessage("[email protected]", "[email protected]", "smbJob", eBody); 
    MyMailMessage.IsBodyHtml = true; 
    try 
    { 
     SmtpClient SMTPServer = new SmtpClient(); 
     SMTPServer.Send(MyMailMessage); 
     return true; 
    } 
    catch 
    { 
     return false; 
    } 
} 

回答

0

對於具有問題的人,我設法解決它:

1)這是正確的web.config的設置(替換「[email protected]」你的「GoDaddy的」電子郵件地址

<system.net> 
<mailSettings> 
    <smtp from="[email protected]"> 
     <network host="relay-hosting.secureserver.net" port="25"/> 
    </smtp> 
</mailSettings> 

據我瞭解,「GoDaddy的」不允許從第三方賬戶發送郵件,如Gmail(後和他們住在一起聊天),不要有寫用戶名& passowrd和它不通過SSL。

您從地址應該是你的「GoDaddy的」電子郵件地址

0

我不確定這是否是您需要的確切代碼,但應該讓您朝着正確的方向前進。確保你正在使用正確的使用指令。

System.Net.Mail.MailMessage mail = 
     new System.Net.Mail.MailMessage("[email protected]", "[email protected]"); 

try 
{ 
    SmtpClient client = new SmtpClient("smtp.office365.com", 587); 
    client.Credentials = new System.Net.NetworkCredential() 
    { 
     UserName = "[email protected]", 
     Password = "password" 
    }; 
    client.EnableSsl = true; 
} 
catch 
{ 
    display some error from here 
} 
+0

電子郵件發送的loclHost工作,這個問題開始了,當我上傳的網站,「GoDaddy的」託管。 –