我编写了下一个自定义PHP函数来通过SMTP邮件服务器发送邮件.
function send($format = 'text'){
$smtpServer = 'mail.mymailserver.com.mx';
$port = '25';
$timeout = '60';
$username = 'myuser';
$password = 'mypassword';
$localhost = 'www.mydomain.com.mx';
$newLine = "\r\n";
$smtpConnect = fsockopen( $smtpServer, $port, $errno, $errstr, $timeout );
fputs( $smtpConnect,'AUTH LOGIN'.$newLine );
fputs( $smtpConnect, base64_encode( $username ) . $newLine );
fputs( $smtpConnect, base64_encode( $password ) . $newLine );
fputs( $smtpConnect, 'HELO ' . $localhost . $newLine );
fputs( $smtpConnect, 'MAIL FROM: ' . $this->from . $newLine );
fputs( $smtpConnect, 'RCPT TO: ' . …Run Code Online (Sandbox Code Playgroud)