2016-08-18 203 views
1

我是PHPMailer的新手。它在我的本地主機上運行良好,但不在現場。phpmailerException消息'無效的地址'

我得到這個錯誤:

Fatal error: Uncaught exception 'phpmailerException' with message 'Invalid address: ' in /directoryhere/test/public_html/scripts/phpmailer/class.phpmailer.php:498 Stack trace: #0 /directoryhere/test/public_html/scripts/phpmailer/class.phpmailer.php(438): PHPMailer->AddAnAddress('to', '', '') #1 /directoryhere/test/public_html/scripts/include.php(189): PHPMailer->AddAddress('', '') #2 /directoryhere/test/public_html/forgot.php(49): send_mail() #3 /directoryhere/test/public_html/index.php(141): include('/home1/test...') #4 {main} thrown in /directoryhere/test/public_html/scripts/phpmailer/class.phpmailer.php on line 498

這是代碼行

/directoryhere/test/public_html/scripts/phpmailer/class.phpmailer.php:498

if (!self::ValidateAddress($address)) { 
     $this->SetError($this->Lang('invalid_address').': '. $address); 
     if ($this->exceptions) { 
     throw new phpmailerException($this->Lang('invalid_address').': '.$address); 
     } 
     if ($this->SMTPDebug) { 
     echo $this->Lang('invalid_address').': '.$address; 
     } 
     return false; 
    } 

/directoryhere/test/public_html/scripts/phpmailer/class.phpmailer.php(438)

public function AddAddress($address, $name = '') { 
    return $this->AddAnAddress('to', $address, $name); 
    } 

任何人都可以幫助我這可能是什麼原因?

+0

我需要一個新的郵件主機? –

+0

該錯誤消息顯示您根本沒有傳送電子郵件地址,因此請檢查您的調用代碼,而不是PHPMailer。 – Synchro

+0

嗯,你扔的地址是什麼**? – m02ph3u5

回答

0

@Synchro @ m02ph3u5謝謝你指出了!它現在運行良好。問題在於提交代碼。電子郵件的值爲空,但當頁面加載時提交按鈕正在觸發。所以我做的是首先加載表單,如果電子郵件輸入是空的,如果不是空的,則提交按鈕被啓用並準備開火。

我只是說行此代碼提交前在這裏和調用郵件功能:

if(isset($_POST["retrieve"])) { //name of button 

//submission and calling mail function here 

}