PHP email script
ik doe al een aardige lange tijd aan web design en coding maar ik snap het php emailen maar niet.
ik heb al een formulier (form) gemaakt
Quote:
<form action="" method="post">
<h2>REGISTER TO <span class="red"><strong>My Site</strong></span></h2>
<label for="firstname">First Name</label>
<input type="text" id="firstname" name="firstname" placeholder="enter your first name...">
<label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname" placeholder="enter your first name...">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="choose a username...">
<label for="email">Email</label>
<input type="text" id="email" name="email" placeholder="enter your email...">
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="choose a password...">
<button type="submit">REGISTER</button>
</form>
<h2>REGISTER TO <span class="red"><strong>My Site</strong></span></h2>
<label for="firstname">First Name</label>
<input type="text" id="firstname" name="firstname" placeholder="enter your first name...">
<label for="lastname">Last Name</label>
<input type="text" id="lastname" name="lastname" placeholder="enter your first name...">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="choose a username...">
<label for="email">Email</label>
<input type="text" id="email" name="email" placeholder="enter your email...">
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="choose a password...">
<button type="submit">REGISTER</button>
</form>
Maar nu heb ik een php script nodig om de mail te verzenden maar ik weet niet hoe dat moet. Kan iemand mij helpen of eventueel een kant en klare script aanleveren die is aangepast aan mijn formulier.
GR Jeffrey
Gewijzigd op 29/09/2014 22:11:04 door Jeffrey Bongers
Je zou de mail() functie in PHP kunnen gebruiken, of zelfs losse script-pakketten zoals PHPmailer.
Gewijzigd op 29/09/2014 22:23:03 door - Ariën -
Ik heb PHPmailer al gebruikt maar daarin zitten heel veel fouten of ik doe iets verkeerd. heb het ook gelijk van de server afgepleurd.
Wat gaat er fout dan?
Gewijzigd op 29/09/2014 22:32:42 door - Ariën -
er komen verschillende fout codes tevoorschijn die zeggen dat in die line 348 dacht ik iets met NET/SMTP was en dan weer in een andere .. steeds verschillend
Gewoon een text proberen te verzenden naar een e-mailadres.
Dit werkt altijd bij mij en daarna uitelkaar halen en het dynamisch maken.
We snappen je frustraties, die hebben we allemaal nog weleens.
Samen kunnen we je wel helpen.
Dit staat op de website (github) van PHPmailer
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$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';
}
?>
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$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';
}
?>
Je zult een SMTP-server/port moeten opgeven als je isSMTP() gebruikt.
Rickert Bombaklats op 29/09/2014 22:36:44:
Probeer het eerst eens los zonder je andere scripts eromheen.
Gewoon een text proberen te verzenden naar een e-mailadres.
Dit werkt altijd bij mij en daarna uitelkaar halen en het dynamisch maken.
We snappen je frustraties, die hebben we allemaal nog weleens.
Samen kunnen we je wel helpen.
Dit staat op de website (github) van PHPmailer
Gewoon een text proberen te verzenden naar een e-mailadres.
Dit werkt altijd bij mij en daarna uitelkaar halen en het dynamisch maken.
We snappen je frustraties, die hebben we allemaal nog weleens.
Samen kunnen we je wel helpen.
Dit staat op de website (github) van PHPmailer
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$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';
}
?>
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]', 'Joe User'); // Add a recipient
$mail->addAddress('[email protected]'); // Name is optional
$mail->addReplyTo('[email protected]', 'Information');
$mail->addCC('[email protected]');
$mail->addBCC('[email protected]');
$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';
}
?>
die heb ik ook precies zo erop gezet met mijn configuratie maar hij bleef errors geven of het niet doen.
Misschien wel handig om te vertellen welke errors je krijgt?
Fatal error: require(): Failed opening required 'PHPMailerAutoload.php' (include_path='.:/opt/php-5.5/pear') in /home/u576256333/index.php on line 72
Vertaald: "Er is geen bepaald bestand of directory"
Heb je PHPmailer zelf ook gedownload, in plaats van alleen deze code uitgeprobeerd te hebben?
Gewijzigd op 29/09/2014 22:52:29 door - Ariën -
Lees wel de comments in het script anders leer je er niets van natuurlijk.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
// Eerst gaan we de error reporting aanzetten zodat we kunnen zien wat er misgaat
error_reporting(E_ALL & ~E_NOTICE);
// We gaan de autoloader inladen zodat we alles uit de class kunnen gebruiken
require 'PHPMailerAutoload.php';
// We maken een nieuw object aan zodat we een e-mail kunnen gaan versturen
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // We willen HEEL graag zien wat er gebeurd en misschien fout gaat
$mail->isSMTP(); // We gaan een e-mail sturen via een andere server, Google in dit geval
$mail->Host = 'smtp.gmail.com'; // Hoe heet de server waar we vanaf willen sturen?
$mail->SMTPAuth = true; // Ja we willen de STMP gebruiken van een andere server
$mail->Username = '[email protected]'; // Jou gebruikersnaam van gmail incl. @gmail.com
$mail->Password = 'en-jou-wachtwoord'; // Jou wachtwoord voor Gmail
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = '[email protected]'; // Dit is de afzender van de e-mail
$mail->FromName = 'Jou-naam'; // En jou naam, dit voorkomt dat het gezien wordt als SPAM
$mail->addAddress('[email protected]', 'Joe User'); // Naar wie moet het toe?
$mail->isHTML(true); // Wordt de e-mail in HTML of niet?
$mail->Subject = 'Here is the subject'; // Jou onderwerp
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; // Hier jou HTML inhoud
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; // En hier alles zonder HTML, maar dit is niet verplicht
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
// Eerst gaan we de error reporting aanzetten zodat we kunnen zien wat er misgaat
error_reporting(E_ALL & ~E_NOTICE);
// We gaan de autoloader inladen zodat we alles uit de class kunnen gebruiken
require 'PHPMailerAutoload.php';
// We maken een nieuw object aan zodat we een e-mail kunnen gaan versturen
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // We willen HEEL graag zien wat er gebeurd en misschien fout gaat
$mail->isSMTP(); // We gaan een e-mail sturen via een andere server, Google in dit geval
$mail->Host = 'smtp.gmail.com'; // Hoe heet de server waar we vanaf willen sturen?
$mail->SMTPAuth = true; // Ja we willen de STMP gebruiken van een andere server
$mail->Username = '[email protected]'; // Jou gebruikersnaam van gmail incl. @gmail.com
$mail->Password = 'en-jou-wachtwoord'; // Jou wachtwoord voor Gmail
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->From = '[email protected]'; // Dit is de afzender van de e-mail
$mail->FromName = 'Jou-naam'; // En jou naam, dit voorkomt dat het gezien wordt als SPAM
$mail->addAddress('[email protected]', 'Joe User'); // Naar wie moet het toe?
$mail->isHTML(true); // Wordt de e-mail in HTML of niet?
$mail->Subject = 'Here is the subject'; // Jou onderwerp
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; // Hier jou HTML inhoud
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; // En hier alles zonder HTML, maar dit is niet verplicht
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
en PHPmailer heb ik ook gedownload en heb ik unpacked in mn server
In welke directory heb je PHPmailer uitgepakt, en waar staat je script?
ik heb mn server en adress veranderd in *server* en *adress* alleen in deze tekst er staat bij mij dus wel de server en het adress
Toevoeging op 29/09/2014 23:03:08:
Gewoon waar mijn index.php staat daar zie ik alle files o.a. PHPmailerautoload.php
En dan kan je vanuit je webroot, waar je index.php staat gewoon "PHPmailer/PHPmailerautoload.php" in je require() gebruiken.
Je moet niet jou eigen server invullen bij de SMTP he. Je moet doen van Gmail gebruiken (als je een gmail account hebt)
Post je gehele script nu eens die je hebt aangepast.
Dat script moet je tussen deze tags zetten (zonder spaties)
Fatal error: require(): Failed opening required 'PHPMailer/PHPMailerAutoload.php' (include_path='.:/opt/php-5.5/pear') in /home/u576256333/index.php on line 72
Heb je anders geen screenshot van je mappenstructuur?
Quote:
$mail->isSMTP(); // We gaan een e-mail sturen via een andere server, Google in dit geval
$mail->Host = 'smtp.gmail.com'; // Hoe heet de server waar we vanaf willen sturen?
$mail->SMTPAuth = true; // Ja we willen de STMP gebruiken van een andere server
$mail->Username = '[email protected]'; // Jou gebruikersnaam van gmail incl. @gmail.com
$mail->Password = 'secret'; // Jou wachtwoord voor Gmail
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->Host = 'smtp.gmail.com'; // Hoe heet de server waar we vanaf willen sturen?
$mail->SMTPAuth = true; // Ja we willen de STMP gebruiken van een andere server
$mail->Username = '[email protected]'; // Jou gebruikersnaam van gmail incl. @gmail.com
$mail->Password = 'secret'; // Jou wachtwoord voor Gmail
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
krijg ik deze error:
Quote:
2014-09-29 21:21:53 Connection: opening to smtp.gmail.com:587, t=10, opt=array ( ) 2014-09-29 21:21:53 Connection: opened 2014-09-29 21:21:53 SERVER -> CLIENT: 220 mx.google.com ESMTP pn5sm17009890wjc.4 - gsmtp 2014-09-29 21:21:53 CLIENT -> SERVER: EHLO *adress* 2014-09-29 21:21:53 SERVER -> CLIENT: 250-mx.google.com at your service, [31.170.165.253] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2014-09-29 21:21:53 CLIENT -> SERVER: STARTTLS 2014-09-29 21:21:53 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2014-09-29 21:21:53 CLIENT -> SERVER: EHLO *adress* 2014-09-29 21:21:53 SERVER -> CLIENT: 250-mx.google.com at your service, [31.170.165.253] 250-SIZE 35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2014-09-29 21:21:53 CLIENT -> SERVER: AUTH LOGIN 2014-09-29 21:21:53 SERVER -> CLIENT: 334 VXNlcm5hbWU6 2014-09-29 21:21:53 CLIENT -> SERVER: ZDkwcmVjQGdtYWlsLmNvbQ== 2014-09-29 21:21:53 SERVER -> CLIENT: 334 UGFzc3dvcmQ6 2014-09-29 21:21:53 CLIENT -> SERVER: Q09OTk9SMzIxMTIz 2014-09-29 21:21:54 SERVER -> CLIENT: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 pn5sm17009890wjc.4 - gsmtp 2014-09-29 21:21:54 SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and then try again. 534-5.7.14 Learn more at 534 5.7.14 https://support.google.com/mail/bin/answer.py?answer=78754 pn5sm17009890wjc.4 - gsmtp 2014-09-29 21:21:54 CLIENT -> SERVER: QUIT 2014-09-29 21:21:54 SERVER -> CLIENT: 221 2.0.0 closing connection pn5sm17009890wjc.4 - gsmtp 2014-09-29 21:21:54 Connection: closed 2014-09-29 21:21:54 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.
Misschien eens zinvol om de foutmeldingen te lezen, er staan zelf linkjes in verwerkt ;-)