Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialryan champin
16,836 Pointsphp mailer issue(with code)
i posted earlier about an issue with my phpmailer. So all the code works untill i add the code to link the phpmailer file and ad the mail() object..
''' <?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$name = trim($_POST["name"]);
$email = trim($_POST["email"]);
$phone = trim($_POST["phone"]);
$company_name = trim($_POST["company_name"]);
$cityState = trim($_POST["cityState"]);
$website = trim($_POST["website"]);
$years = trim($_POST["years"]);
$competitors = trim($_POST["competitors"]);
$target = trim($_POST["target"]);
$desc = trim($_POST["desc"]);
$range = trim($_POST["range"]);
if(isset($_POST['website-job'])){
$website = "true";
}
else{
$website = "false";
}
if(isset($_POST['app-job'])){
$app = "true";
}
else{
$app = "false";
}
if(isset($_POST['branding-job'])){
$branding = "true";
}
else{
$branding = "false";
}
if(isset($_POST['print-job'])){
$print = "true";
}
else{
$print = "false";
}
if(isset($_POST['marketing-job'])){
$marketing = "true";
}
else{
$marketing = "false";
}
if(isset($_POST['corporate-job'])){
$corporate = "true";
}
else{
$corporate = "false";
}
if ($name == "" OR $phone == "" OR $email == "" OR $desc == "" OR $target == "" OR $range == "0.00"){
echo "You must answer all fields with an *";
exit;
}
foreach( $_POST as $value ){
if( stripos($value,'Content-Type:') !== FALSE){
echo "There was a problem with your ISP :(";
exit;
}
}
/*
require_once("inc/class.phpmailer.php");
$mail = new PHPMailer();
if($mail->ValidateAddress($email)){
echo "You must enter a valid email!";
exit;
}*/
$email_body = "";
$email_body = $email_body . "Name: " . $name . "\n";
$email_body = $email_body . "Email: " . $email . "\n";
$email_body = $email_body . "Message: " . $message;
header("Location: contact.php?status=thanks");
exit;
}
$current = 'contact';
include("inc/header.php");
?> <body>
<!-- TITLE SECTION -->
<section class="heading-lg center hero" id="top">Meet Our Gate Keeper. He Bites.
<h4 class="center">Plan Your Project Below</h4>
</section>
<?php include("inc/navbar.php");
if (isset($_GET["status"]) AND $_GET["status"] == "thanks") { ?>
<p>Thanks for the Email, we'll be in touch!</p>
<?php } else { ?>
<div class="container width">
<section class="heading-sm center margin-top">The Basics</section>
<form method="post" action="contact.php">
<!-- THE BASICS -->
<div class="row contact-spacing">
<div class="col col-sm-4">
<input type="text" class="form-control" name="name" placeholder="Full Name*">
</div>
<div class="col col-sm-4">
<input type="text" class="form-control" name="email" placeholder="Email*">
</div>
<div class="col col-sm-4">
<input type="text" class="form-control" name="phone" placeholder="Phone*">
</div>
</div>
<!-- YOUR COMPNAY -->
<div class="row border-bottom padding-bottom">
<div class="col col-sm-4">
<input type="text" class="form-control" name="company_name" placeholder="Company Name">
</div>
<div class="col col-sm-4">
<input type="text" class="form-control" name="cityState" placeholder="City, State">
</div>
<div class="col col-sm-4">
<input type="text" class="form-control" name="website" placeholder="Website">
</div>
<input type="text" style="display: none;">
</div>
<section class="heading-sm center margin-top">Your Company</section>
<div class="row">
<div class="col col-sm-4">
<input type="text" class="form-control" name="years" placeholder="Years iN bUSINESS">
</div>
<div class="col col-sm-4">
<input type="text" class="form-control" name="competitors" placeholder="Competition*">
</div>
<div class="col col-sm-4">
<input type="text" class="form-control" name="target" placeholder="Target Audience*">
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col col-sm-12">
<textarea class="form-control margin-bottom" name="desc" rows="3"placeholder="Company Description*"></textarea>
</div>
</div>
</div>
<!-- CHECKBOXES -->
<label class="heading-sm center">Type Of Project</label>
<div class="row">
<div class="col-sm-2 center">
<div class="padding">
<div class="check-wrapper">
<input type="checkbox" id="c1" name="corporate-job" value="corporate-job">
<label for="c1"><span class="check">
<p class="center">Corporate</p></span></label>
</div>
</div>
</div>
<div class="col-sm-2 center">
<div class="padding">
<div class="check-wrapper">
<input type="checkbox" id="c2" name="website-job" value="website-job">
<label for="c2"><span class="check"><p class="center">Website</p></span></label>
</div>
</div>
</div>
<div class="col-sm-2 center">
<div class="padding">
<div class="check-wrapper">
<input type="checkbox" id="c3" name="app-job" value="app-job">
<label for="c3"><span class="check"><p class="center">App</p></span></label>
</div>
</div>
</div>
<div class="col-sm-2 center">
<div class="padding">
<div class="check-wrapper">
<input type="checkbox" id="c4" name="branding-job" value="branding-job">
<label for="c4"><span class="check"><p class="center">Branding</p></span></label>
</div>
</div>
</div>
<div class="col-sm-2 center">
<div class="padding">
<div class="check-wrapper">
<input type="checkbox" id="c5" name="print-job" value="print-job">
<label for="c5"><span class="check"><p class="center">Print</p></span></label>
</div>
</div>
</div>
<div class="col-sm-2 center">
<div class="padding">
<div class="check-wrapper">
<input type="checkbox" id="c6" name="marketing-job" value="marketing-job">
<label for="c6"><span class="check"><p class="center">Marketing</p></span></label>
</div>
</div>
</div>
</div>
<!-- BUDEGET SLIDER -->
<div class="row">
<div class="col col-sm-4"></div>
<div id="slider" class="col-sm-4 center italic">
<h4 class="center">Project Budget</h4>
<input type="range" name="range" min="0" max="10000" step="50" value="0" />
<output for="range" class="heading-sm" ></output>
</div>
<div class="col col-sm-4"></div>
</div>
<!-- WHERED YOU FIND US -->
<label class="heading-sm center">Have you been stalking us? We hope so...</label>
<div class="row">
<div class="col-sm-3"></div>
<div class="col-sm-6">
<input type="text" class="form-control" name="reference" placeholder="Where did you find us?">
</div>
<div class="col-sm-3"></div>
</div>
<!-- SUBMIT -->
<div class="row">
<div class="col col-sm-4"></div>
<div class="col col-sm-4">
<button type="submit" class="btn btn-default contact-btn btn-block">Submit</button>
</div>
<div class="col-sm-4"></div>
</div>
</div> </form>
</div>
<?php } ?>
<?php include("inc/footer.php"); ?>
<?php include("inc/scripts.php"); ?> </body> </html>
'''
11 Answers
Chris Wiley
11,327 PointsYes! adding a copy of the Autoload file into the mailer folder with phpmailer.php resolved the line 575 fatal error for me.
ryan champin
16,836 Pointsno...it just sends me to a completely blank page...but when i comment those two out it sends me to the thank you version of the page
Michal Kurtulík
9,203 Pointsif you use example files you must have require_once("inc/phpmailer/class.phpmailer.php");
ryan champin
16,836 Pointsyeah i know that from the video but when i use the require once it just displays nothing...thres no errors in my chrome inspection console....so im lost lol
ryan champin
16,836 Pointsi use the require_once in it but i had to comment it out to get the page to work
Michal Kurtulík
9,203 Pointsphp error not show in chrome console you must check our log on server usuali named _error.log and placed on root or ./log dir. To display all errors you need to:
- Have these lines in the PHP script you're calling from the browser (typically index.php):
error_reporting(E_ALL); ini_set('display_errors', 1);
2.(a) Make sure that this script has no syntax errors
—or—
2.(b) Set display_errors = On in your php.ini
Otherwise, it can't even run those 2 lines!
ryan champin
16,836 Pointsim really sorry but im a bit onfused..how can i check my custom code....im just adapting their use of the form to mine....on your server? im rly new to php sorry
Michal Kurtulík
9,203 Pointstray use in frst line on your app if you see completely blank page
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1)
?>
ryan champin
16,836 Pointsoh man thats awesome thnks.....but these are the errors that are coming up now....they're all related to the file path being messed up but i've checked it 100 times and the filepath im using is correct...i even changed it and took it out of the folder to just have in it my main project folder so theres less of a chance for mess-ups.... but heres the errors
'''Warning: require(PHPMailerAutoload.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/For The Bold v2/inc/class.phpmailer.php on line 575
Fatal error: require(): Failed opening required 'PHPMailerAutoload.php' (include_path='.:/Applications/MAMP/bin/php/php5.4.10/lib/php') in /Applications/MAMP/htdocs/For The Bold v2/inc/class.phpmailer.php on line 575'''
Chris Wiley
11,327 PointsI received this same fatal error doing the tutorial. I wonder if the Autoload must be added to the mailer file in inc or get its own folder with this newer version of mailer? I noticed the test file Randy is using in the video is not part of the new download zip. I am using the XAMPP with firefox and chrome as a back up. Both show the line 575 fatal error.
ryan champin
16,836 Pointsjust to be more clear....this is my php
''' require_once("inc/phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); '''
and this my error
Warning: require_once(inc/phpmailer/class.phpmailer.php): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/For The Bold v2/contact.php on line 76
Fatal error: require_once(): Failed opening required 'inc/phpmailer/class.phpmailer.php' (include_path='.:/Applications/MAMP/bin/php/php5.4.10/lib/php') in /Applications/MAMP/htdocs/For The Bold v2/contact.php on line 76
Hampton Paulk
5,093 Pointsmamp can sometimes have issues with permissions and relative paths. Take a look at this SO answer and see if it helps you at all.
Michal Kurtulík
9,203 PointsMichal Kurtulík
9,203 Pointsyou dont have any error message?