发送邮件SMTP:在未连接GMAIL的情况下称为Mail() [英] Send mail SMTP: Called Mail() without being connected GMAIL
问题描述
我尝试发送所有表格的电子邮件,将门更改为465/587,已经检查了安全性较低的应用程序帐户设置,已经在我的主机中检查的是PHP扩展处于活动状态,并且所有这些确定,都已经尝试发送使用hotmail帐户来确保问题出在代码中,已经将单引号与双引号进行了交易,已经检查了密码以确保正确,我已完成了所有工作,并仍然收到以下消息:
I have tried to send email all forms , changed the doors to 465/587 , already checked the less secure applications account settings , already checked in my hosting is the PHP extensions are active and all this " OK" , already tried send with hotmail account to make sure that the problem was in the code, already traded single quotes with double quotes , already checked the password to make sure that is correct , I have done everything and still keep getting the following message :
邮件错误:以下发件人地址失败:taxcoe@gmail.com:
调用Mail()却未连接
Mail error: The following From address failed: taxcoe@gmail.com : Called Mail() without being connected
页面 enviar.php
<?php
$Nome = $_POST["Nome"]; // Pega o valor do campo Nome
$assunto = $_POST["Assunto"]; // Pega o valor do campo Telefone
$Email = $_POST["Email"]; // Pega o valor do campo Email
$Mensagem = $_POST["Mensagem"]; // Pega os valores do campo Mensagem
// Variável que junta os valores acima e monta o corpo do email
$Vai = "Nome: $Nome\n\nE-mail: $Email\n\nAssunto: $assunto\n\nMensagem: $Mensagem\n";
require_once("phpmailer/class.phpmailer.php");
define('GUSER', 'taxcoe@gmail.com'); // <-- Insira aqui o seu GMail
define('GPWD', '****'); // <-- Insira aqui a senha do seu GMail
function smtpmailer($para, $de, $de_nome, $assunto, $corpo) {
global $error;
$mail = new PHPMailer();
$mail->IsSMTP(); // Ativar SMTP
$mail->SMTPDebug = 0; // Debugar: 1 = erros e mensagens, 2 = mensagens apenas
$mail->SMTPAuth = true; // Autenticação ativada
$mail->SMTPSecure = 'tls'; // SSL REQUERIDO pelo GMail
$mail->Host = 'smtp.gmail.com'; // SMTP utilizado
$mail->Port = 587; // A porta 587 deverá estar aberta em seu servidor
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($de, $de_nome);
$mail->Subject = $assunto;
//$mail->Body = $corpo;
$mail->MsgHTML(true);
$mail->AddAddress($para);
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Mensagem enviada!';
return true;
}
}
// Insira abaixo o email que irá receber a mensagem, o email que irá enviar (o mesmo da variável GUSER),
//o nome do email que envia a mensagem, o Assunto da mensagem e por último a variável com o corpo do email.
if (smtpmailer('taxcoe@gmail.com', 'taxcoe@gmail.com', 'Nome do Enviador', 'Contato do Site', $Vai)) {
Header("location:http://www.pauloroberto.xyz"); // Redireciona para uma página de obrigado.
}
if (!empty($error)) echo $error;
?>
页面 index.html
<!DOCTYPE html>
<html>
<head>
<title>Email</title>
<meta name="description" content="">
<meta charset="utf-8">
</head>
<body>
<form action="enviar.php" method="post">
<label for="Nome">Nome:</label>
<input type="text" name="Nome" size="35" />
<label for="Email">E-mail:</label>
<input type="text" name="Email" size="35" />
<label for="Fone">Assunto:</label>
<input type="text" name="Fone" size="35" />
<label for="Mensagem">Mensagem:</label>
<textarea name="Mensagem" rows="8" cols="40"></textarea>
<input type="submit" name="Enviar" value="Enviar" />
</form>
</body>
</html>
推荐答案
现在尝试一下,我尝试并获得成功
try this now I try and get success
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tsl'; tls
$mail->Host = "hostname";
$mail->Port = 587;
$mail->IsHTML(true);
$mail->SetLanguage("tr", "phpmailer/language");
$mail->CharSet ="utf-8";
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($de, $de_nome);
$mail->AddAddress($para);
$mail->Subject = "You have Message From Site";
$mail->Body = $Vai;
$mail->Send();
这篇关于发送邮件SMTP:在未连接GMAIL的情况下称为Mail()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!