Phpmailer in combinatie met Office365 smtp

Pagina: 1
Acties:
  • 970 views

Vraag


Acties:
  • 0 Henk 'm!

  • ThaFishy
  • Registratie: Mei 2020
  • Laatst online: 28-04 22:33
Mijn vraag

Sinds deze week heb ik de mail ingesteld via office 365. Nu had ik nog een contactformulier op de website van mijn ouders. Deze gebruikt PHPMailer. Alleen deze werkt niet meer. Nu heb ik al lopen stack overflowen en googlen maar kon niks werkbaars vinden.

Hieronder mijn php:

code:
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
 * This example shows settings to use when sending over SMTP with TLS and custom connection options.
 */

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');

require '../PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer;

$name = "";
$phone = "";
$email = "";
$subject ="";
$message ="";

if(isset($_POST['name'])) {
    $name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
}

if(isset($_POST['phone'])) {
    $phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING);
}
 
if(isset($_POST['email'])) {
    $email = $_POST['email'];
}
 
if(isset($_POST['subject'])) {
    $subject = filter_var($_POST['subject'], FILTER_SANITIZE_STRING);
}

if(isset($_POST['message'])) {
    $message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
}

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'smtp.office365.com';

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Custom connection options
$mail->SMTPOptions = array (
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "info@email.nl";

//Password to use for SMTP authentication
$mail->Password = "password";

//Set who the message is to be sent from
$mail->setFrom($email, $name);

//Set who the message is to be sent to
$mail->addAddress($recipient, "Name");

//Set the subject line
$mail->Subject = "$subject";

$mail->Body = "$message";

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}


Ik krijg deze foutmelding bij het afvuren van het script.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2022-03-18 13:46:00 Connection: opening to smtp.office365.com:587, timeout=300, options=array()
2022-03-18 13:46:00 Connection: opened
2022-03-18 13:46:00 SERVER -> CLIENT: 220 AM0PR10CA0035.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 18 Mar 2022 13:45:59 +0000
2022-03-18 13:46:00 CLIENT -> SERVER: EHLO website.nl
2022-03-18 13:46:00 SERVER -> CLIENT: 250-AM0PR10CA0035.outlook.office365.com Hello [178.128.240.240]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-STARTTLS250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2022-03-18 13:46:00 CLIENT -> SERVER: STARTTLS
2022-03-18 13:46:00 SERVER -> CLIENT: 220 2.0.0 SMTP server ready
2022-03-18 13:46:00 CLIENT -> SERVER: EHLO website.nl
2022-03-18 13:46:00 SERVER -> CLIENT: 250-AM0PR10CA0035.outlook.office365.com Hello [178.128.240.240]250-SIZE 157286400250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH LOGIN XOAUTH2250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2022-03-18 13:46:00 CLIENT -> SERVER: AUTH LOGIN
2022-03-18 13:46:00 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2022-03-18 13:46:00 CLIENT -> SERVER: [credentials hidden]
2022-03-18 13:46:00 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2022-03-18 13:46:00 CLIENT -> SERVER: [credentials hidden]
2022-03-18 13:46:06 SERVER -> CLIENT: 535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [AM0PR10CA0035.EURPRD10.PROD.OUTLOOK.COM]
2022-03-18 13:46:06 SMTP ERROR: Password command failed: 535 5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [AM0PR10CA0035.EURPRD10.PROD.OUTLOOK.COM]
SMTP Error: Could not authenticate.
2022-03-18 13:46:06 CLIENT -> SERVER: QUIT
2022-03-18 13:46:06 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2022-03-18 13:46:06 Connection: closed
SMTP Error: Could not authenticate.
Mailer Error: SMTP Error: Could not authenticate.


Ik heb de inloggegevens correct en in de office365 omgeving heb ik het vinkje aanstaan om smtp te gebruiken.

Wie kan mij uit de brand helpen?

Alle reacties


Acties:
  • 0 Henk 'm!

  • RobIII
  • Registratie: December 2001
  • Niet online

RobIII

Admin Devschuur®

^ Romeinse Ⅲ ja!

(overleden)
ThaFishy schreef op vrijdag 18 maart 2022 @ 15:03:
Wie kan mij uit de brand helpen?
Nou, sorry, maar niet zo ;)

Wanneer je code post, post dan enkel relevante(!) code. 120 regels code is (veel) teveel van het goede. Maar ik mis ook alle eigen inzet wat je zélf al ondernomen hebt om je probleem op te lossen (zie onze Quickstart).
ThaFishy schreef op vrijdag 18 maart 2022 @ 15:03:
Nu heb ik al lopen stack overflowen en googlen maar kon niks werkbaars vinden.
(Zie ook onze quickstart): Waar zocht je dan op? Wat vond je dan wél? Want ik vind meer dan voldoende.

Open gerust een nieuw topic maar hou dan even bovenstaande en voorgenoemde quickstart in je achterhoofd :)

[ Voor 22% gewijzigd door RobIII op 18-03-2022 16:31 ]

There are only two hard problems in distributed systems: 2. Exactly-once delivery 1. Guaranteed order of messages 2. Exactly-once delivery.

Je eigen tweaker.me redirect

Over mij


Dit topic is gesloten.