/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] PHP email new MySQL entry not working.

I’ve asked this question before but used ajax and it produced some weird behaviour. I’m hoping someone could write a simple php mail function for me. Here’s what I have at the moment:

[code=html]<?php

if (isset($_POST[‘subme’])) {
//define the receiver of the email
$to = ‘[email protected]’;
//define the subject of the email
$subject = ‘Test email’;
//define the message to be sent. Each line should be separated with n
$message .= $_POST[‘naam’];
//define the headers we want passed. Note that they are separated with rn
$headers = “From: [email protected]: [email protected]”;
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );
}

?>
<!DOCTYPE html>
<html>
<head>
<title>Factuur informatie.</title>
<meta name=”viewport” content=”width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no”>
<meta charset=”utf-8″>
<meta http-equiv=”content-type” content=”text/html; charset=utf-8″ />
<link rel=”stylesheet” href=”css/bootstrap.min.css”>
<link rel=”stylesheet” href=”css/animate.css”>
</head>
<body style=”background-color: white”>

<div class=”row”>
<div class=”col-sm-6 col-sm-offset-3″>
<div class=”well” style=”margin-top: 10%;”>
<h3>Voor uw factuur hebben wij de volgende informatie nodig.</h3>
<form action=”insert.php” method=”post” role=”form” data-toggle=”validator” class=”shake”>
<div class=”row”>
<div class=”form-group down col-sm-6″>
<label for=”name” class=”h4″>Voor en achternaam.</label>
<input name=”naam” type=”text” class=”form-control” id=”name” placeholder=”Voornaam Achternaam” required data-error=”Vergeet deze niet!”>
<div class=”help-block with-errors”></div>
</div>
<div class=”form-group down col-sm-6″>
<label for=”birth” class=”h4″>Geboortedatum</label>
<input name=”geboortedatum” type=”text” class=”form-control” id=”birth” placeholder=”22-12-1961″ required data-error=”Vergeet deze niet!”>
<div class=”help-block with-errors”></div>
</div>
<div class=”form-group down col-sm-6″>
<label for=”BSN” class=”h4″>BSN</label>
<input name=”BSN” type=”text” class=”form-control” id=”BSN” placeholder=”Burgerservicenummer” required data-error=”Vergeet deze niet!”>
<div class=”help-block with-errors”></div>
</div>
<div class=”form-group down col-sm-6″>
<label for=”email” class=”h4″>Email</label>
<input name=”email” type=”email” class=”form-control” id=”email” placeholder=”Enter email” required>
<div class=”help-block with-errors”></div>
</div>
<div class=”form-group down col-sm-6″>
<label for=”adres” class=”h4″>Email</label>
<input name=”adres” type=”text” class=”form-control” id=”adres” placeholder=”Adres” required>
<div class=”help-block with-errors”></div>
</div>
<div class=”form-group down col-sm-6″>
<label for=”telefoon” class=”h4″>Email</label>
<input name=”telefoon” type=”text” class=”form-control” id=”telefoon” placeholder=”0612345678″ required>
<div class=”help-block with-errors”></div>
</div>
</div>

<button value=”Submit” name=”subme” style=”background-color: #75963c;” type=”submit” id=”form-submit” class=”btn btn-success btn-lg pull-right “>Submit</button>
<div id=”msgSubmit” class=”h3 text-center hidden”></div>
<div class=”clearfix”></div>
</form>

</div>
</div>
<div class=”col-sm-6 col-sm-offset-3″>
<img style=”width: 300px; display: block; margin: 0 auto; padding-top:20px;” src=”lessstress.gif”>
</div>
</div>

<style type=”text/css”>

@media (max-width: 900px) {
.down {
width: 95%;
}

</style>

</body>
<script type=”text/javascript” src=”js/jquery-1.11.2.min.js”></script>
<script type=”text/javascript” src=”js/validator.min.js”></script>

</html>[/code]

Please note that the php email is not working. It won’t sent anything.

Here is my script for the sql database.

[code=html] <html>
<body>
<?php
$con = mysql_connect(“databaseip”,”username”,”password”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(“databasename”, $con);

$sql=”INSERT INTO nametable (naam, geboortedatum, BSN, email, adres, telefoon) VALUES(‘$_POST[naam]’,’$_POST[geboortedatum]’,’$_POST[BSN]’,’$_POST[email]’,’$_POST[adres]’,’$_POST[telefoon]’)”;

if (!mysql_query($sql,$con))
{
die(‘Error: ‘ . mysql_error());
}

echo “1 record added”;

mysql_close($con)
?>
</body>
</html>[/code]

After / or before the form is submitted I want to receive the data in email so to be notified that someone has submitted a new form. Right now it is -only submitting to my database and not emailing me the data. Hopefully someone can help me get this functional. I am not a web developer and I’ve spent three days on getting this to this stage. All help is HIGHLY appreciated. I just want to get this functional.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@silent_helperauthorJul 13.2016 — We can close this too. I figured it out!
Copy linkTweet thisAlerts:
@TrainJul 13.2016 — In thread tools, above your first post, you as the original poster, can mark the thread resolved.
Copy linkTweet thisAlerts:
@ginerjmJul 13.2016 — Please stop using the @ character. What's the point of capturing the result of your call to the mail function (which nobody here was going to write for you as you asked) if you SUPPRESS it with the @?

And of course, you should definitely stop using the MySQL_* functions. See the manual.
Copy linkTweet thisAlerts:
@NogDogJul 13.2016 — Just a point of order, the @ operator won't affect the assigning of the result to the variable, only the generation of an error code/message -- which, however, is usually better handled by the 'display_errors' setting and/or the error_reporting() function or 'error_reporting' setting; as opposed to just sweeping it under the rug and then not noticing when something bad is happening that you should fix. ?
Copy linkTweet thisAlerts:
@patcoJul 16.2016 — Hello. I can't really find the problem. Can you show us what was wrong?
×

Success!

Help @silent_helper spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...