Jump to content
php.lv forumi

php email sender


Prova1ver
 Share

Recommended Posts

Labdien,

 

Sāku taisīt projektu uz twitter bootstrap bāzes, vēlējos vienā no sadaļām izveidot contact us formu , kas pēc lietotāja formu aizpildes aizsūtīs datuus uz manu epasta adresi izmantojot gmail smtp.

varbūt jau ir gatavs skripts, meklēju google atradu dažus , bet varbūt jūs kādu varat ieteikt.

 

Paldies.

Link to comment
Share on other sites

Izveidoju contact.html formu kas savienojas ar contact-form-submission.php, bet man kaut k'a neiet varb'ut k'ads var izpalīdzēt izlabot kļūdu. Paldies
 
contact.html
<!DOCTYPE HTML>
<html>
<head>
	<title>My basic contact form</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>

	<div class="container">
	
        <div class="page-header">
            <h1>Contact Me</h1>
        </div>
<?php

		// check for a successful form post
		if (isset($_GET['s'])) echo "<div class=\"alert alert-success\">".$_GET['s']."</div>";

		// check for a form error
		elseif (isset($_GET['e'])) echo "<div class=\"alert alert-error\">".$_GET['e']."</div>";

?>
        <form method="POST" action="contact-form-submission.php" class="form-horizontal">
            <div class="control-group">
                <label class="control-label" for="input1">Name</label>
                <div class="controls">
                    <input type="text" name="contact_name" id="input1" placeholder="Your name">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input2">Email Address</label>
                <div class="controls">
                    <input type="text" name="contact_email" id="input2" placeholder="Your email address">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="input3">Message</label>
                <div class="controls">
                    <textarea name="contact_message" id="input3" rows="8" class="span5" placeholder="The message you want to send to me."></textarea>
                </div>
            </div>
            <div class="form-actions">
                <input type="hidden" name="save" value="contact">
                <button type="submit" class="btn btn-primary">Send</button>
            </div>
        </form>
        
    </div>
        
</body>
</html>

 

contact-form-submission.php

 

<?php
// check for form submission - if it doesn't exist then send back to contact form  
if (!isset($_POST['save']) || $_POST['save'] != 'contact') { 
    header('Location: contact-form.php'); exit; 
} 
     
// get the posted data 
$name = $_POST['contact_name']; 
$email_address = $_POST['contact_email']; 
$message = $_POST['contact_message']; 
     
// check that a name was entered 
if (empty($name)) 
    $error = 'You must enter your name.'; 
// check that an email address was entered 
elseif (empty($email_address))  
    $error = 'You must enter your email address.'; 
// check for a valid email address 
elseif (!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $email_address)) 
    $error = 'You must enter a valid email address.'; 
// check that a message was entered 
elseif (empty($message)) 
    $error = 'You must enter a message.'; 
         
// check if an error was found - if there was, send the user back to the form 
if (isset($error)) { 
    header('Location: contact-form.php?e='.urlencode($error)); exit; 
} 
         
// write the email content 
$email_content = "Name: $name\n"; 
$email_content .= "Email Address: $email_address\n"; 
$email_content .= "Message:\n\n$message"; 
     
// send the email 
mail ("mas@mans.lv", "Epasta Title", $email_content); 
     
// send the user back to the form 
header('Location: contact-form.php?s='.urlencode('Thank you for your message.')); exit;  
  
?>  

 

 

Link to comment
Share on other sites

to funkciju augstakais izmantos 3-4 x vispar, negribas iedzilināties phpmailera un meiginat to savienot ar bootstrap. Projekts nav nopietns

 

uz šo momentu mail funkcija ir tas kas vajadzigs.

kļudu vienalga neesmu sapratis

Edited by Prova1ver
Link to comment
Share on other sites

paņem no tā .php faila to rindiņu, kur tiek izsaukts

 

mail()

 

saliec visur gatavas, reālas vērtības un izpildi

 

ja nestrādā, tad sistēmā nestrādā mail()

ja strādā, tad liec klāt savas mežģīnes pa vienai un  skaties tālāk

Link to comment
Share on other sites

Kas par sviestu... cilvēks prasa kā STD-liba funkciju padarīt strādājošu, bet jūs viņam metat sejā kkkādas abstrakcijas...

 

> — Hei, kā lai stringā ieliek mainīgā vērtību?

> — Izmanto Smarty!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...