我是 PHP 新手,我必須使用 phpmailer 發送簡歷。我發現錯誤為“Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting ”。請更改代碼。我在我的代碼中使用 phpmailer。它在我第一次做的時候有效,但現在這段代碼會出錯。<?php include('header.php');require 'PHPMailerAutoload.php';$message='';if(isset($_POST["submit"])){ $path='upload/'.$_FILES["resume"]["name"]; move_uploaded_file($_FILES["resume"]["tmp_name"], $path); $mail = new PHPMailer;$mail->SMTPDebug = 0; // Enable verbose debug output$mail->isSMTP(); // mailer to use SMTP$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers$mail->SMTPAuth = true; // Enable SMTP authentication$mail->Username = '[email protected]'; // SMTP username$mail->Password = 'mypasswordgoeshere'; // SMTP password$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted$mail->Port = 465; // TCP port to connect to$mail->From=$_POST['email'];$mail->FromName=$_POST['name'];$mail->setFrom($_POST['email']);$mail->addAddress('[email protected]'); $mail->AddCC($_POST['name'],$_POST['email']);$mail->WordWrap=50;$mail->AddAttachment($path);$mail->Subject='application for job'; // Add a recipient // Name is optional$mail->addReplyTo($_POST['email']);$mail->isHTML(true); // Set email format to HTML//$mail->Subject = $_POST['subject'];$mail->Body = $_POST['message'];$mail->AltBody = $_POST['message'];if(!$mail->send()) { echo '<script>alert("Message could not be sent.")</script>'; echo 'Mailer Error: ' . $mail->ErrorInfo;} else { echo '<script>alert("Message has been sent"); window.location.href="career.php"; </script>';}}?>
- 2 回答
- 0 關注
- 995 瀏覽
添加回答
舉報
0/150
提交
取消