-1
我的網站有一個奇怪的問題。 我運行的每一個分鐘檢查一些條件在C#代碼,如果條件爲真,發送這個代碼的電子郵件:郵件差異代碼c#php
SmtpClient client = new SmtpClient("localhost");
MailAddress from = new MailAddress("[email protected]", "Site", System.Text.Encoding.UTF8);
// Specify the message content.
MailMessage message = new MailMessage();
message.From = from;
// Set destinations for the e-mail message
for(int x = 1; x <= 5; x++){
if(to_array[x].ToString().Length > 0){
message.To.Add(to_array[x]);
}
}
//message.Bcc.Add(this.email_bcc);
message.Body = this.message;
// Include some non-ASCII characters in body and subject.
message.Body += Environment.NewLine;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = this.subject;
message.SubjectEncoding = System.Text.Encoding.UTF8;
try{
client.Send(message);
}catch(System.Exception e){
string[] myemail = new string[]{"[email protected]"};
Email email = new Email("Email Exception: \r\n" + e.ToString() + "\r\n\r\n" + this.message + "\r\n", myemail, "Mysql Exception - Saeg SRL");
email.send();
}
這個腳本工作正常,併發送正確的電子郵件。 我必須在php中製作一個類似的東西進入同一個服務器,我嘗試使用phpmailer在c#中複製腳本的設置,但是這段代碼不起作用,沒有發送電子郵件。爲什麼?
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "localhost"; // SMTP server
$mail->From = '[email protected]';
$mail->FromName = 'Saeg';
$mail->AddAddress('[email protected]');
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = 'Riepilogo';
$mail->Body = "Riepilogo";
$mail->AltBody = "Riepilogo";
if ($mail->Send()){
//ok
}
else{
?>
<script type="text/javascript">
alert('<?php echo ("error");?>');
window.close();
</script>
<?php
}
我也曾嘗試:
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "localhost"; // SMTP server
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->Username = "[email protected]";
$mail->Password = "password";
$mail->From = '[email protected]';
$mail->FromName = 'Saeg';
$mail->AddAddress('[email protected]');
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = 'Riepilogo';
$mail->Body = "Riepilogo";
$mail->AltBody = "Riepilogo";
if ($mail->Send()){
//ok
}
else{
?>
<script type="text/javascript">
alert('<?php echo ("error");?>');
window.close();
</script>
<?php
}
沒有SMTP發送電子郵件,而不是我的例如域[email protected]發送,如果我發送此郵件給[email protected]沒有按不發送電子郵件。
我不知道這是否是你真正的代碼,但你忘了 '在'$ MAIL-> AddAddress(' 電子郵件@電子郵件。它);' – Havsmonstret
謝謝,但不是問題,因爲我已經改變了電子郵件地址的隱私,正確的文本@Havsmonstret – WebDesigner