I am trying to send a mail using PHP.
But it is just not working. I contacted my IT teacher, a few IT nerds I know, colleges at work, but they all just couldn't help me. I know there are a lot of questions on stackoverflow about this already, that's why I waited so long to post this. But i looked at all the questions about PHP's mail() function I could find, and none solved my problem. I am pretty desperate.
The thing is that it doesn't work using my code to create the mail, but it also doesn't work when just using the function with plain text. So that got me thinking the problem must be server-side. I contacted one.com (which is where my website is hoasted), but they couldn't help me. They said the mail() function should just work. They did give me this:
Sushant: - Mail Host: mailout.one.com
Sushant: - Port: 25
Sushant: - Authentication: None/False
Sushant: - Security: None/False
Sushant: - Username: email account of your domain e.g. info@mydomain.com
Sushant: - Password: password of your email account
I don't know what to do with this information. I did try to edit some of the things in the php.ini file (mail.add_x_header, mail.log, SMTP, smtp_port, sendmail_from, sendmail_path) using the ini_set() function. also that didn't solve my problem.
My full code:
(sorry for the dutch language)
$onderwerp = "E-mail adres controlleren";
$bericht ="
U bent succesvol geregistreerd bij theovisser.com.<br>
Nu kunt u alle verstuurde nieuwsbrieven lezen. Ook kunt u<br>
nieuwe nieuwsbrieven meteen zien, nog voordat ze bij op op de mat liggen!<br><br>
Om uw account te activeren moet u alleen nog wel de onderstaande code<br>
invoeren.<br>
E-mail code: " .$_SESSION['controle_code']. "<br><br>
Groeten,<br>
Samuël Visser
";
// Regels in berichten mogen nooit langer zijn als 70 caracters (PHP regel).
// Hiermee worden alle regels die langer als 70 caracters zijn ingekort.
$bericht = wordwrap($bericht, 70);
// Verstuur de mail
if(!isset($_SESSION['mail_verstuurd']))
{
if(mail($email,$onderwerp,$bericht)){
echo 'Er is een mail verstuurd naar uw adres.<BR><BR>';
$_SESSION['mail_verstuurd']='true';
}else{
echo 'Het versturen van de mail is mislukt.<BR><BR>';
}
}
This doesn't do anything at all.
And the weirdest this is that this doesn't work too:
mail('samuvisser@gmail.com','test','dit is een test');
Can you guys solve my problem? I really don't know what I am doing wrong.
EDIT:
Using the suggestion from @ojovirtual to use the PHPMailer libary, I got the following error:
2014-11-04 13:27:48 Connection: opening to mailout.one.com:25, t=300, opt=array ( ) 2014-11-04 13:28:10 SMTP ERROR: Failed to connect to server: A connection attempt failed because the connected party did not properly respond after a period of time , or established connection failed because connected host has not replied. (10060) 2014-11-04 13:28:10 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed
The italic style text in the error was Dutch, this is translated to English. Might be a bit different as the original English translation.
This is the setup I used, following the data i got from one.com:
require($main .'PHPMailer-master/PHPMailerAutoload.php');
$mail = new PHPMailer;
$mail->SMTPDebug=3;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mailout.one.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = false; // Enable SMTP authentication
$mail->Username = 'noreply@theovisser.com'; // SMTP username
$mail->Password = 'won't show that here :)'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->From = 'noreply@theovisser.com';
$mail->FromName = 'Samuël Visser';
$mail->addAddress('samuvisser@gmail.com', 'Sammie gast'); // Add a recipient
//$mail->addAddress('ellen@example.com'); // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');
$mail->WordWrap = 50; // Set word wrap to 50 characters
//$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
I used the code recommended on the PHPMailer page.
Thanks for your help!