Pandee Posted January 26, 2021 Share Posted January 26, 2021 I have Swift/symfony mail installed and sample code setup. When I require_once to a working PHP page, the page becomes blank in a browser, If i remove it from the require the website works. Lints can't find any errors or syntax issues in the code. Its on gitlab. What should i do? Below is the page where I send an email out and the environment I am in Ubuntu PHP7 SwiftMail 6.0^ <?php require_once '/vendor/autoload.php'; session_start(); // Create the Transport $transport = (new Swift_SmtpTransport('localhost', 465)) ->setUsername(noreply@example.com) ->setPassword(password); // Create the Mailer using your created Transport $mailer = new Swift_Mailer($transport); function sendVerificationEmail($email, $token) { global $mailer; $body = '<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Test mail</title> </head> <body> <div class="wrapper"> <p>Thank you for signing up on our site. Please click on the link below to verify your account:.</p> <a href="https://tadoo.club/verify-email.php?token=' . $token . '">Verify Email!</a> </div> </body> </html>'; // Create a message $message = (new Swift_Message('Verify your email')) ->setFrom(noreply@example.com) ->setTo($email) ->setBody($body, 'text/html'); // Send the message $result = $mailer->send($message); ?> Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/ Share on other sites More sharing options...
requinix Posted January 26, 2021 Share Posted January 26, 2021 A blank page means a fatal PHP error. What do your server error logs say? Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1583997 Share on other sites More sharing options...
Pandee Posted January 26, 2021 Author Share Posted January 26, 2021 6 minutes ago, requinix said: A blank page means a fatal PHP error. What do your server error logs say? Sorry about the slow reply, I checked and its this "AH01071: Got error 'PHP message: PHP Parse error: syntax error, unexpected '@', expecting ')' in /var/www/vhosts/tadoo.club/httpdocs/sendEmails.php on line 6'" Was I not meant to use @ in an user email address? Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1583998 Share on other sites More sharing options...
requinix Posted January 26, 2021 Share Posted January 26, 2021 Email addresses definitely have @s in them. Do you happen to be new to PHP? Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1583999 Share on other sites More sharing options...
Pandee Posted January 26, 2021 Author Share Posted January 26, 2021 I see. Yes Im new and im learning on my own as a hobby. Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1584000 Share on other sites More sharing options...
requinix Posted January 26, 2021 Share Posted January 26, 2021 Great. ->setUsername(noreply@example.com) That email address in there is supposed to be a string. That means it needs quotes. See how '/vendor/autoload.php' and 'localhost' and 'Verify your email' are? Those are also strings. The password in ->setPassword(password) also needs to be a string, but it could be that you removed your password and replaced it with that just for the post, so for all I know the version you have in front of you is already a string. Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1584001 Share on other sites More sharing options...
Pandee Posted January 26, 2021 Author Share Posted January 26, 2021 2 minutes ago, requinix said: Great. ->setUsername(noreply@example.com) That email address in there is supposed to be a string. That means it needs quotes. See how '/vendor/autoload.php' and 'localhost' and 'Verify your email' are? Those are also strings. The password in ->setPassword(password) also needs to be a string, but it could be that you removed your password and replaced it with that just for the post, so for all I know the version you have in front of you is already a string. Ahh I see.. I thought it was weird when the example had no quotes. I think this should do the trick. Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1584002 Share on other sites More sharing options...
requinix Posted January 26, 2021 Share Posted January 26, 2021 Just now, Pandee said: Ahh I see.. I thought it was weird when the example had no quotes. I think this should do the trick. The example might have been using a constant. Those are pre-defined values like define('USERNAME', 'noreply@example.com'); // or const USERNAME = 'noreply@example.com'; In the first one, the constant is created with a function, and the name of the constant needs to be a string because it's passed as a value to the define() function. The second one shows a special syntax for creating constants, where the name of the constant doesn't have to be a string because that's how the syntax works: name of constant = value of constant. Note that for both of those syntaxes, the email value is still a string. 1 Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1584003 Share on other sites More sharing options...
Pandee Posted January 26, 2021 Author Share Posted January 26, 2021 *salute* Thanks for the help and recommendations to look at the logs! Appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/312046-swiftmail-issue-intergrating-it-to-php-project/#findComment-1584005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.