Erro sendmail on PHP


#1

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

                    // multiple recipients
		$to  = 'wesley.sto.rodrigues@gmail.com' . ', '; // note the comma
		//$to .= 'wez@example.com';

		// subject
		$subject = 'Birthday Reminders for August';

		// message
		$message = '
		<html>
		<head>
		 <title>Birthday Reminders for August</title>
		</head>
		<body>
		<p>Here are the birthdays upcoming in August!</p>
		<table>
		 <tr>
		  <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
		 </tr>
		 <tr>
		  <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
		 </tr>
		 <tr>
		  <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
		 </tr>
		</table>
		</body>
		</html>
		';

		// To send HTML mail, the Content-type header must be set
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

		// Additional headers
		$headers .= '';
		//$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
		//$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
		//$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

		// Mail it
		mail($to, $subject, $message, $headers);

PHP Mail() Function not working
#2

Hi there,
i have a send email in my site and it works. u can try the code i use:

<?php
$name = $_POST ['name'];

$email = $_POST ['email'];
?>

<?php
$to = "your email";
$subject = "...";
$message = "...";
$header = "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=iso-8859-1\n";
$header .= "From: $email\n";
mail($to, $subject, $message, $header);
echo "E-mail sent.";
?>

i took from a forum some time ago, hope it help u out

[update] it didnt take the right spaces in the code…idk why… so try separate it by lines.


#3

nothing. not function sendmail free 000webhost


#4

Hi @shimatani!

It appears that one of our mailing servers is temporarily down. Please try again later.

We are sorry for inconvenience :sweat:


#5

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


#6

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


#7

What errors do you encounter? :slight_smile:


#8

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

                    $emails = "email local";
                    $to = "send-email@gmail.com";
                    $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);

#9

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.


#10

PHPMailer not function too. i did try and nothing


#11

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.


#12

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

<?php

// Inclui o arquivo class.phpmailer.php localizado na pasta class
require_once("class/class.phpmailer.php");

// 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 = 'smtp.seudominio.com.br'; // Endereço do servidor SMTP (Autenticação, utilize o host smtp.seudomínio.com.br)
      $mail->SMTPAuth   = true;  // Usar autenticação SMTP (obrigatório para smtp.seudomínio.com.br)
      $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('seu@e-mail.com.br', 'Nome'); //Seu e-mail
 $mail->AddReplyTo('seu@e-mail.com.br', 'Nome'); //Seu e-mail
 $mail->Subject = 'Assunto';//Assunto do e-mail


 //Define os destinatário(s)
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 $mail->AddAddress('e-mail@destino.com.br', 'Teste Locaweb');

 //Campos abaixo sĂŁo opcionais 
 //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 //$mail->AddCC('destinarario@dominio.com.br', 'Destinatario'); // Copia
 //$mail->AddBCC('destinatario_oculto@dominio.com.br', '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.
 //$mail->MsgHTML(file_get_contents('arquivo.html'));

 $mail->Send();
 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
}
?>

#13

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


#14

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
$mail->Send();

// After the send
print_r($mail->ErrorInfo);
printLogs($smtpLogs);

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.


PHP-Mail with Joomla
#15

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.


#16

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?


#17

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

Yes.


#18

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


#19

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


#20

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.