Invalid Address in PHPMailer

Hi,

I want to send an email with PHP page itself it was working fine before  after i add extra textbox in that form  user needs to add mentor E-mail id
but it shows error
"Invalid address "
"Notice: Undefined variable: mentor_email1 in"

require '../PHPMailer/class.phpmailer.php';

 if (!isset($_POST['mentoremail'])) 
	 {
	 
	$mentor_email1 ="";
	$mentor_email1= $_POST['mentoremail'];
	}

$mail->addAddress($mentor_email1);
  if(!$mail->send()) {
        echo '<div class="alert alert-danger">Email error:bla bla n.</div>';
    }

<div class="control-group">
			  <label class="control-label" for="descinput">Mentor Email ID(subordinate)</label>
			  <div class="controls">

			
			 <input type="text"  name="mentoremail" size="30"    >
			  
			  
			  </div>
			</div>

<div class="controls">
                     <button id="submit" class="btn btn-primary" type="submit" name="submit" value="Login">Apply</button>
               </div>

Open in new window

prashanth agsoftware engineer Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Loganathan NatarajanLAMP DeveloperCommented:
hide this line

// $mentor_email1 ="";
	$mentor_email1= $_POST['mentoremail'];

Open in new window

0
KimputerCommented:
Actually, this will fail if previous page is correctly set up:

$mail->addAddress($mentor_email1);

That's because $mentor_email1 is never assigned anything if the value $_POST['mentoremail] IS SET!
For now, the quickest way is to change
 if (!isset($_POST['mentoremail']))
to
 if (isset($_POST['mentoremail']))
0
prashanth agsoftware engineer Author Commented:
Hi,

I changed as you mentioned  but it shows same error
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

prashanth agsoftware engineer Author Commented:
Notice: Undefined variable: mentor_email in and
Invalid address:
0
prashanth agsoftware engineer Author Commented:
How to post data to the same page ?
example
$mentor_email1= $_POST['mentoremail'];

Open in new window

0
Marcus BointonCommented:
Your code makes very little sense. Try this:

 if (isset($_POST['mentoremail'])) 
	 {
require '../PHPMailer/class.phpmailer.php';
	$mentor_email1= $_POST['mentoremail'];
$mail->addAddress($mentor_email1);
  if(!$mail->send()) {
        echo '<div class="alert alert-danger">Email error:bla bla n.</div>';
    }
}


<div class="control-group">
			  <label class="control-label" for="descinput">Mentor Email ID(subordinate)</label>
			  <div class="controls">

			
			 <input type="text"  name="mentoremail" size="30"    >
			  
			  
			  </div>
			</div>

<div class="controls">
                     <button id="submit" class="btn btn-primary" type="submit" name="submit" value="Login">Apply</button>
               </div>

Open in new window


I assume you have cut out all the other stuff that PHPMailer needs. You're also using an old version of PHPMailer; Get the latest from github.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Loganathan NatarajanLAMP DeveloperCommented:
can you post the complete code?
0
prashanth agsoftware engineer Author Commented:
@Squinky

I made changes as you mentioned but it shows

Fatal error: Call to a member function addAddress() on a non-object in
Notice: Undefined variable: mail in
0
Marcus BointonCommented:
As I said - it looks like you've left out all your other code - you're missing a `$mail = new PHPMailer;`.
0
prashanth agsoftware engineer Author Commented:
thanks Squinky and Loganathan Natarajan
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.