Erro sendmail on PHP

2 posts were merged into an existing topic: Send Email Help

I can not use sendmail through php. how do I do?

What errors do you encounter? :slight_smile:

not had errors, but not send email to what i config here

                    $emails = "email local";
                    $to = "";
                    $subject = "ALERTS";
                    $message = "TEST";
                    $header = "MIME-Version: 1.0\n";
                    $header .= "Content-type: text/html; charset=iso-8859-1\n";
                    $header .= "From: $emails\n";
                    mail($to, $subject, $message, $header);

If you want to send via Gmail, the mail() function is unlikely to work. In any case, it has some pretty severe security problems, so the best advice is to avoid it entirely.

Use a good quality PHP library instead. There are many, and the main ones are PHPMailer and SwiftMailer.

PHPMailer not function too. i did try and nothing

It’s been working just fine for me for the last five months on 000webhost, so try again! I got 000webhost, PHPMailer and Gmail working together just a couple of days ago. If you’re having trouble with it, show us the smallest possible PHP script that illustrates your problem.

1 Like

i did try with various code PHPMalier and nothing. Here down.


// Inclui o arquivo class.phpmailer.php localizado na pasta class

// Inicia a classe PHPMailer
$mail = new PHPMailer(true);

// Define os dados do servidor e tipo de conexão
// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
$mail->IsSMTP(); // Define que a mensagem será SMTP

 try {
      $mail->Host = ''; // Endereço do servidor SMTP (Autenticação, utilize o host smtp.seudomí
      $mail->SMTPAuth   = true;  // Usar autenticação SMTP (obrigatório para smtp.seudomí
      $mail->Port       = 587; //  Usar 587 porta SMTP
      $mail->Username = 'usuário de smtp'; // Usuário do servidor SMTP (endereço de email)
      $mail->Password = 'senha de smtp'; // Senha do servidor SMTP (senha do email usado)

 //Define o remetente
 // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=    
 $mail->SetFrom('', 'Nome'); //Seu e-mail
 $mail->AddReplyTo('', 'Nome'); //Seu e-mail
 $mail->Subject = 'Assunto';//Assunto do e-mail

 //Define os destinatário(s)
 $mail->AddAddress('', 'Teste Locaweb');

 //Campos abaixo são opcionais 
 //$mail->AddCC('', 'Destinatario'); // Copia
 //$mail->AddBCC('', 'Destinatario2`'); // Cópia Oculta
 //$mail->AddAttachment('images/phpmailer.gif');      // Adicionar um anexo

 //Define o corpo do email
 $mail->MsgHTML('corpo do email'); 

 ////Caso queira colocar o conteudo de um arquivo utilize o método abaixo ao invés da mensagem no corpo do e-mail.

 echo "Mensagem enviada com sucesso</p>\n";

//caso apresente algum erro é apresentado abaixo com essa exceção.
}catch (phpmailerException $e) {
  echo $e->errorMessage(); //Mensagem de erro costumizada do PHPMailer

sorry the “//” coments in portuguese brazilian. because im brasilian, all right? thanks.

Looks like you’re missing the authentication scheme:

$mail->SMTPSecure = 'tls'; // Matches your 587 port

If that does not help, look at your error info and turn on SMTP logging:

// Before the send
$smtpLogs = [];
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'logHandler';

// Your send goes here

// After the send

function logHandler($log, $level)
    global $smtpLogs;

    $smtpLogs[] = trim($log);

function printLogs(array $logs)
    echo implode("\n", $logs) . "\n";

If you are still stuck, please provide your SMTP logs - I cannot help without those.

As pointed out in my earlier post, a mailing server is down and developers will fix it as soon as possible. PHP mail() function will not work until issue is fixed unfortunately :sweat:

Also, SMTP is not supported on 000webhost. From our websites you can send e-mails using only mail() function.

Works just fine for me, with a range of external mail providers. Do you mean that 000webhost don’t provide their own SMTP mail servers?

Do you mean that 000webhost don’t provide their own SMTP mail servers?


1 Like

I was assuming that @shimatani is trying their own SMTP server with PHPMailer. I was guessing that is not an alias for a 000webhost server :slightly_smiling_face:

@halfer i have the gmail mail SMTP. will not function?

You have to make a settings change in Gmail:

  • Go to the cog icon in the top-right
  • Click on the Settings menu entry
  • Click on the Accounts and Import tab
  • Get to the Google Accounts section
  • Find the Apps With Account Access section
  • Turn on “Allow less secure apps”

If that’s not it, then I won’t help further until I see your SMTP logs.

1 Like

i did try, not functioned too! i searched on internet, in the Google, but nothing too

but the directory what “/PHPMailer/”, isn’t more depreced. i have with “class.phpmailer.php”. the now require “phpmailer.php”, version 6.0.3 in the github. or i wrong?

the scripts php, they are same or diferent?

Yes, use 6.*, and follow the example here. I would guess your earlier example used PHPMailer 5.2. That will work, but it’s better to use the latest versions.

i will try, thanks my friend